Flutter AppBar IconButton 导航
Flutter AppBar IconButton Navigation
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: buildAppBar(),
backgroundColor: Colors.white,
body: Body(),
);
}
AppBar buildAppBar() {
return AppBar(
backgroundColor: Colors.white,
elevation: 0,
leading: IconButton(
padding: EdgeInsets.only(left: kDefaultPadding),
icon: SvgPicture.asset("assets/icons/menu.svg"),
onPressed: () {},
),
actions: <Widget>[
Container(
width: 200,
alignment: Alignment(-0.4, 0.0),
child: Text('JOA',
textAlign: TextAlign.center,
style:
TextStyle(
color: kTextColor,
fontSize: 33,
),
),
),
IconButton(
padding: EdgeInsets.symmetric(horizontal: kDefaultPadding),
icon: SvgPicture.asset("assets/icons/logon.svg"),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => WelcomeScreen(),
),
);
},
),
],
);
}
}
此处错误代码
lib/home/home_screen.dart:47:17:错误:未为 class 'HomeScreen'.[=11 定义 getter 'context' =]
- 'HomeScreen' 来自 'package:movie_app/home/home_screen.dart' ('lib/home/home_screen.dart').
尝试将名称更正为现有 getter 的名称,或定义一个 getter 或名为 'context' 的字段。 上下文,
Appbar后如何添加context
在你的脚手架中:
appBar: buildAppBar(context),
然后在您的应用栏小部件中:
AppBar buildAppBar(BuildContext context)
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: buildAppBar(),
backgroundColor: Colors.white,
body: Body(),
);
}
AppBar buildAppBar() {
return AppBar(
backgroundColor: Colors.white,
elevation: 0,
leading: IconButton(
padding: EdgeInsets.only(left: kDefaultPadding),
icon: SvgPicture.asset("assets/icons/menu.svg"),
onPressed: () {},
),
actions: <Widget>[
Container(
width: 200,
alignment: Alignment(-0.4, 0.0),
child: Text('JOA',
textAlign: TextAlign.center,
style:
TextStyle(
color: kTextColor,
fontSize: 33,
),
),
),
IconButton(
padding: EdgeInsets.symmetric(horizontal: kDefaultPadding),
icon: SvgPicture.asset("assets/icons/logon.svg"),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => WelcomeScreen(),
),
);
},
),
],
);
}
}
此处错误代码
lib/home/home_screen.dart:47:17:错误:未为 class 'HomeScreen'.[=11 定义 getter 'context' =]
- 'HomeScreen' 来自 'package:movie_app/home/home_screen.dart' ('lib/home/home_screen.dart').
尝试将名称更正为现有 getter 的名称,或定义一个 getter 或名为 'context' 的字段。 上下文,
Appbar后如何添加context
在你的脚手架中:
appBar: buildAppBar(context),
然后在您的应用栏小部件中:
AppBar buildAppBar(BuildContext context)