showModalBottomSheet() 中的持久状态小部件?

时间:2021-02-09 07:17:53

标签: flutter dart statefulwidget flutter-showmodalbottomsheet

我正在尝试构建一个显示有状态 Explorer 小部件的底部工作表。我希望资源管理器小部件在 showModalBottomSheet() 的调用之间保持其状态,并尝试使用 GlobalKey 来实现它。如何检索 ExplorerState 并将其传递给 showModalBottomSheet() 以进行构建?

class BottomNavBar extends StatefulWidget {
  BottomNavBar({
    Key key,
  }) : super(key: key);

  @override
  _BottomNavBarState createState() => _BottomNavBarState();
}

class _BottomNavBarState extends State<BottomNavBar> {
  GlobalKey<ExplorerState> _sheetKey = GlobalKey<ExplorerState>();
  Explorer _explorer;

  @override
  void initState() {
    _explorer = Explorer(key: _sheetKey);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        decoration: BoxDecoration(
          boxShadow: [
            BoxShadow(color: Colors.black38, spreadRadius: 0, blurRadius: 10),
          ],
        ),
        child: ClipRRect(
            borderRadius: BorderRadius.only(
              topRight: Radius.circular(10.0),
            ),
            child: BottomAppBar(
                child: Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                IconButton(
                    icon: Icon(Icons.menu),
                    onPressed: () {
                      showModalBottomSheet(
                          useRootNavigator: false,
                          isDismissible: true,
                          context: context,
                          builder: (context) => ????
                    }),
                IconButton(
                  icon: Icon(Icons.search),
                  onPressed: () {},
                )
              ],
            ))));
  }
}

我显然是

0 个答案:

没有答案