如何设置底部纸的最小尺寸,当底部表包含导航器时
我想设计一个底部表,在底部表格内有一个子弹药。 但是,现在我希望我的底部表格与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
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在
约束
上使用showmodalbottomsheet
,它将提供一些对尺寸的控制。You can use
constraints
onshowModalBottomSheet
, it will provide some control over sizing.