MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('老孟'),),)
MaterialApp(
title: '老孟',onGenerateTitle: (context) {
var local = Localizations.localeOf(context);
if (local.languageCode == 'zh') {
return '老孟';
}
return 'laomeng';
},...
)
- 路由为
/
,home
不为null则使用home
。
- 使用
routes
指定的路由。
- 使用
onGenerateRoute
生成的路由,处理除home
和routes
以外的路由。
- 如果上面都不匹配则调用
onUnknownRoute
。
MaterialApp(
routes: {
'container': (context) => ContainerDemo(),'fitted': (context) => FittedBoxDemo(),'icon': (context) => IconDemo(),},initialRoute: '/',home: Scaffold(
appBar: AppBar(
title: Text('老孟'),onGenerateRoute: (RouteSettings routeSettings){
print('onGenerateRoute:$routeSettings');
if(routeSettings.name == 'icon'){
return MaterialPageRoute(builder: (context){
return IconDemo();
});
}
},onUnknownRoute: (RouteSettings routeSettings){
print('onUnknownRoute:$routeSettings');
return MaterialPageRoute(builder: (context){
return IconDemo();
});
},...
)
MaterialApp(
theme: ThemeData(
primaryColor: Colors.red
),darkTheme: ThemeData(
primaryColor: Colors.red
),themeMode: ThemeMode.dark,
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
flutter_cupertino_localizations: ^1.0.1
MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,GlobalWidgetsLocalizations.delegate,GlobalCupertinoLocalizations.delegate
],supportedLocales: [
const Locale('zh','CH'),const Locale('en','US'),],...
)
- GlobalMaterialLocalizations.delegate :为Material Components库提供了本地化的字符串和其他值。
- GlobalWidgetsLocalizations.delegate:定义widget默认的文本方向,从左到右或从右到左。
- GlobalCupertinoLocalizations.delegate:为Cupertino(ios风格)库提供了本地化的字符串和其他值。
MaterialApp(
localeListResolutionCallback:
(List<Locale> locales,Iterable<Locale> supportedLocales) {
if (locales.contains('zh')) {
return Locale('zh');
}
return Locale('en');
},...
)
Locale myLocale = Localizations.localeOf(context);
MaterialApp(
debugShowMaterialGrid: true,
MaterialApp(
showPerformanceOverlay: true,
MaterialApp(
debugShowCheckedModeBanner: true,...
)