我创建了以下自定义布局:
class CustomLayout extends StatelessWidget {
final Widget leading;
final String title;
final Widget body;
final List<Widget> bottomBar;
const CustomLayout({
Key key,Widget leading, String title, Widget body, this.bottomBar
}):leading = leading ?? const SizedBox(height: 0,),
title = title ?? "",
body = body ?? const SizedBox(),
super(key: key)
;
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Stack(
alignment: Alignment.topLeft,
children: [
/// Background
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("images/background.jpg"),
fit: BoxFit.cover
)
),
),
/// custom
Column(
children: [
/// SimpleAppbar
SizedBox(
height: (title == "")? 0 : 50,
width: MediaQuery.of(context).size.width,
child: Stack(
alignment: Alignment.centerLeft,
children: [
Center(
child: Text(
title,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 24
),
),
),
Container(
padding: const EdgeInsets.only(left:4.0,top: 4.0),
child: leading,
),
],
),
),
/// body
Expanded(child: body),
/// bottomBar
SizedBox(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: bottomBar == null ? [SizedBox()]:bottomBar,
),
)
],
)
],
),
),
);
}
}
并使用这个布局:
CustomLayout(
leading: IconButton(
icon: Icon(
Icons.arrow_back,
color: Colors.white,
),
onPressed: (){
Navigator.of(context).pop();
},
),
body: // my code
);
领先参数无法按下,我搜索了一些提示,发现应该是我的栈但是我已经检查了很多次。底部条和正文参数仍然可以正常工作。帮帮我!