如何BottomSheet在 Flutter 中以编程方式关闭 Persistent ?还有没有办法只显示持久底部工作表的一部分,用户可以向上拖动工作表以查看完整内容?
下面的代码是显示持久化的底表。
homeScaffoldKey.currentState.showBottomSheet<Null>((BuildContext context) {
return Container(
height: 300.0,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: EdgeInsets.all(16.0),
child: Text(
'Persistent header for bottom bar!',
textAlign: TextAlign.left,
)),
Text(
'Then here there will likely be some other content '
'which will be displayed within the bottom bar',
textAlign: TextAlign.left,
),
],
));
});
Run Code Online (Sandbox Code Playgroud) 我的 xml 文件包含代码:
<com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
android:id="@+id/bnve"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimary"
app:itemIconTint="@drawable/bottom_navigation_colors"
app:itemTextColor="@drawable/bottom_navigation_colors"
app:menu="@menu/bottom_nav_menu" />
Run Code Online (Sandbox Code Playgroud)
我的java文件包含:
BottomNavigationViewEx bnve = (BottomNavigationViewEx)findViewById(R.id.bnve);
Run Code Online (Sandbox Code Playgroud)
它在安卓设备上完美运行。但是当我添加这些行时:
bnve.enableAnimation(false);
bnve.enableShiftingMode(false);
bnve.enableItemShiftingMode(false);
Run Code Online (Sandbox Code Playgroud)
该应用程序因错误而崩溃:
java.lang.RuntimeException: 无法启动活动getClass()' 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2583) 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2665) 在 android.app.ActivityThread.-wrap11(ActivityThread.-wrap11(ActivityThread) .java) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1499) 在 android.os.Handler.dispatchMessage(Handler.java:111) 在 android.os.Looper.loop(Looper.java:207)在 android.app.ActivityThread.main(ActivityThread.java:5765) 在 java.lang.reflect.Method。invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 由:java. lang.NullPointerException:尝试在 com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx.getBottomNavigationItemViews(BottomNavigationViewEx.java:569) 处的空对象引用上调用虚拟方法“java.lang.Class java.lang.Object.getClass()”。 ittianyu.bottomnavigationviewex.BottomNavigationViewEx.enableAnimation(BottomNavigationViewEx.java:341) at com.bimsina.projectchautari.MainActivity.onCreate(MainActivity.java:94) at android.app.Activity.performCreate(Activity.java:6331) at android.app .Instrumentation.callActivityOnCreate(Instrumentation.java:1113)第1113章第1113章ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 由:java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.在 com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx.getBottomNavigationItemViews(BottomNavigationViewEx.java:569) at com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx.enableAnimation(BottomNavigationViewEx.java:341) 处的空对象引用上的 java.lang.Object.getClass()' 类在 com.bimsina.projectchautari.MainActivity.onCreate(MainActivity.java:94) 在 android.app.Activity.performCreate(Activity.java:6331) 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) …