我有一个脚手架。单击 MoreActionButton 后,我实现了一个 showModalBottomSheet,其中包含操作列表。
class MyScaffold extends StatelessWidget {
final MyFruit apple;
final Widget body;
const MyScaffold({
required this.apple,
required this.body,
super.key,
});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: ...,
body: body,
floatingActionButton: MoreActionsButton(apple),
bottomNavigationBar: ...,
key: key,
);
}
}
其中一个操作需要使用此脚手架主体中的当前信息。这是如何实现的?
不知何故尝试在主体本身中添加 FAB,但这不是预期的结果。任何建议。这是如何实现的?
您可以创建一个方法,该方法将采用如下参数
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MainWidget(
apple: '10 apples',
),
);
}
}
class MainWidget extends StatelessWidget {
final String apple;
const MainWidget({Key? key, required this.apple}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: IconButton(
onPressed: () {
modalBottomSheetMenu(context, apple);
},
icon: Icon(Icons.play_arrow)),
);
}
}
//pass parameters here
void modalBottomSheetMenu(BuildContext context, String someData)
{
showModalBottomSheet(
context: context,
builder: (builder) {
return new Container(
height: 350.0,
color: Colors.transparent, //could change this to Color(0xFF737373),
//so you don't have to change MaterialApp canvasColor
child: new Container(
decoration: new BoxDecoration(
color: Colors.white,
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(10.0),
topRight: const Radius.circular(10.0))),
child: new Center(
child: new Text(someData),//use it inside the bottomsheet
)),
);
});
}