为什么MaterialApp
为我的新屏幕从AppBar
隐藏了后退按钮。我的应用程序中有很多屏幕,我需要在其中使用ThemeData
。为此,我在另一个屏幕上使用了MaterialApp
,但是在back
上看不到任何AppBar()
箭头。
return MaterialApp(
theme: ThemeData(
fontFamily: 'IranSansLight',
textTheme: TextTheme(
headline: TextStyle(fontSize: 72.0, fontWeight: FontWeight.bold, fontFamily: 'IranSansLight'),
title: TextStyle(fontSize: 36.0, fontStyle: FontStyle.italic, fontFamily: 'IranSansLight'),
body1: Theme.of(context).textTheme.caption.copyWith(fontFamily: 'IranSansLight', color: Colors.black)),
),
home: ScopedModel(
model: CounterModel(),
child: Directionality(
textDirection: TextDirection.rtl,
child: Scaffold(
appBar: AppBar(automaticallyImplyLeading:true,title: Text('aaaa'),),
body: Container(
)),
),
),
);
}
答案 0 :(得分:2)
您正在为所有单个屏幕使用MaterialApp
,这不是正确的方法,对于整个应用程序,您只需要一个MaterialApp
。
void main() {
runApp(
MaterialApp(home: HomePage()), // MaterialApp widget should be used only here
);
}
每当需要在第二个屏幕中使用Theme
时,请使用类似以下内容:
@override
Widget build(BuildContext context) {
return Theme(
data: Theme.of(context).copyWith(
// override whatever you need like
textTheme: TextTheme(...),
),
child: Scaffold(),
);
}