gpt4 book ai didi

android - 单击 flutter 中的底部按钮时在半屏中显示选项卡

转载 作者:行者123 更新时间:2023-11-28 23:45:15 25 4
gpt4 key购买 nike

当我点击某个按钮时,我想要使用 flutter 这样的东西,一个选项卡会弹出到屏幕的一半。

Main screen

Nearby Tab

City Tab

最佳答案

您可以通过以下代码实现:

import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.teal,
),
home: new MyHomePage(),
);
}
}

class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
final _scaffoldKey = new GlobalKey<ScaffoldState>();
VoidCallback _showPersBottomSheetCallBack;

@override
void initState() {
super.initState();
_showPersBottomSheetCallBack = _showBottomSheet;
}

void _showBottomSheet() {
setState(() {
_showPersBottomSheetCallBack = null;
});

_scaffoldKey.currentState
.showBottomSheet((context) {
return new Container(
height: 300.0,
color: Colors.tealAccent,
child: new Center(
child: new Text("Hi BottomSheet"),
),
);
})
.closed
.whenComplete(() {
if (mounted) {
setState(() {
_showPersBottomSheetCallBack = _showBottomSheet;
});
}
});
}

void _showModalSheet() {
showModalBottomSheet(
context: context,
builder: (builder) {
return new Container(
color: Colors.tealAccent,
child: new Center(
child: new Text("Hi ModalSheet"),
),
);
});
}

@override
Widget build(BuildContext context) {
return new Scaffold(
key: _scaffoldKey,
appBar: new AppBar(
title: new Text("Flutter BottomSheet"),
),
body: new Padding(
padding: const EdgeInsets.all(20.0),
child: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new RaisedButton(
onPressed: _showPersBottomSheetCallBack,
child: new Text("Persistent"),
),
new Padding(
padding: const EdgeInsets.only(top: 10.0),
),
new RaisedButton(
onPressed: _showModalSheet,
child: new Text("Modal"),
),
],
)),
),
);
}
}

它会创建这样的东西:

ScreenShot

关于android - 单击 flutter 中的底部按钮时在半屏中显示选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52791545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com