如何设置底部纸的最小尺寸,当底部表包含导航器时

发布于 2025-02-08 00:56:37 字数 2891 浏览 1 评论 0原文

我想设计一个底部表,在底部表格内有一个子弹药。 但是,现在我希望我的底部表格与Navigator中的1页的内容相同。我已经尝试了多种方法,但无法得到我想要的东西。向前看,向社区提供帮助,以进一步支持我的理论或如何解决这个问题

这是我的完整代码。

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter(BuildContext context) {
    DemoSubNavigatorPopup.show(context);

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(

        title: Text(widget.title),
      ),
      body: Center(

        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => _incrementCounter(context),
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

class DemoSubNavigatorPopup extends StatelessWidget {
  DemoSubNavigatorPopup({Key? key}) : super(key: key);

  static show(BuildContext context) {
    showModalBottomSheet(
        context: context,
        builder: (context) {
          return DemoSubNavigatorPopup();
        });
  }

  final subNavigatorKey = GlobalKey<NavigatorState>();

  @override
  Widget build(BuildContext context) {
    return Navigator(
      key: subNavigatorKey,
      onGenerateRoute: (setting) {
        return MaterialPageRoute(builder: (context) {
          return Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              TextButton(
                onPressed: () {
                  Navigator.push(context, MaterialPageRoute(builder: (context) {
                    return SubPageScreen();
                  }));
                },
                child: Text('Next SubPage'),
              )
            ],
          );
        });
      },
    );
  }
}

class SubPageScreen extends StatelessWidget {
  const SubPageScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        TextButton(
            onPressed: () {
              Navigator.pop(context);
            },
            child: Text('Back')),
        Text('SubPage')
      ],
    );
  }
}

I want to design a bottomSheet, Inside the bottomSheet there is a subNavigator.
However Now I want my BottomSheet to be the same size as the contents of 1 page in Navigator. I've tried many ways but can't get what I want.Looking forward to help from the community to further support me in theory or how to solve this problem
this is what I want

Here is my full code.

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter(BuildContext context) {
    DemoSubNavigatorPopup.show(context);

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(

        title: Text(widget.title),
      ),
      body: Center(

        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => _incrementCounter(context),
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

class DemoSubNavigatorPopup extends StatelessWidget {
  DemoSubNavigatorPopup({Key? key}) : super(key: key);

  static show(BuildContext context) {
    showModalBottomSheet(
        context: context,
        builder: (context) {
          return DemoSubNavigatorPopup();
        });
  }

  final subNavigatorKey = GlobalKey<NavigatorState>();

  @override
  Widget build(BuildContext context) {
    return Navigator(
      key: subNavigatorKey,
      onGenerateRoute: (setting) {
        return MaterialPageRoute(builder: (context) {
          return Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              TextButton(
                onPressed: () {
                  Navigator.push(context, MaterialPageRoute(builder: (context) {
                    return SubPageScreen();
                  }));
                },
                child: Text('Next SubPage'),
              )
            ],
          );
        });
      },
    );
  }
}

class SubPageScreen extends StatelessWidget {
  const SubPageScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        TextButton(
            onPressed: () {
              Navigator.pop(context);
            },
            child: Text('Back')),
        Text('SubPage')
      ],
    );
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零度℉ 2025-02-15 00:56:37

您可以在约束上使用showmodalbottomsheet,它将提供一些对尺寸的控制。

showModalBottomSheet(
    constraints: BoxConstraints.tight(Size.fromHeight(30)), //Note: it is hard-coded value
    context: context,
    builder: (context) => DemoSubNavigatorPopup());

You can use constraints on showModalBottomSheet, it will provide some control over sizing.

showModalBottomSheet(
    constraints: BoxConstraints.tight(Size.fromHeight(30)), //Note: it is hard-coded value
    context: context,
    builder: (context) => DemoSubNavigatorPopup());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文