示例 github:flutterlayout https://github.com/LiuC520/flutterlayoutgit
連載:flutter佈局-1-columngithub
連載:flutter佈局-2-rowbash
連載:flutter佈局-3-center網絡
連載:flutter佈局-4-containerapp
連載:[flutter佈局-5-Matrix4矩陣變換框架
這個是有狀態的widget,有如下參數dom
this.navigatorKey, // 導航的key
this.home, // 主頁
this.routes = const <String, WidgetBuilder>{},// 路由
this.initialRoute,//初始路由
this.onGenerateRoute,//生成路由
this.onUnknownRoute,//位置路由
this.navigatorObservers = const <NavigatorObserver>[],//導航的觀察者
this.builder,//widget的構建
this.title = '',//設備用於識別用戶的應用程序的單行描述。在Android上,標題顯示在任務管理器的應用程序快照上方,當用戶按下「最近的應用程序」按鈕時會顯示這些快照。 在iOS上,沒法使用此值。 來自應用程序的`Info.plist`的`CFBundleDisplayName`在任什麼時候候都會被引用,不然就會引用`CFBundleName`。要提供初始化的標題,能夠用 onGenerateTitle。
this.onGenerateTitle,//每次在WidgetsApp構建時都會從新生成
this.color,//背景顏色
this.theme,//主題,用ThemeData
this.locale,//app語言支持
this.localizationsDelegates,//多語言代理
this.localeResolutionCallback,//
this.supportedLocales = const <Locale>[Locale('en', 'US')],//支持的多語言
this.debugShowMaterialGrid = false,//顯示網格
this.showPerformanceOverlay = false,//打開性能監控,覆蓋在屏幕最上面
this.checkerboardRasterCacheImages = false,
this.checkerboardOffscreenLayers = false,
this.showSemanticsDebugger = false,//打開一個覆蓋圖,顯示框架報告的可訪問性信息 顯示邊框
this.debugShowCheckedModeBanner = true,//右上角顯示一個debug的圖標
複製代碼
你們能夠新建一個項目,在main.dart文件裏面就能看到這個東西啦ide
* 若是home首頁指定了,routes裏面就不能有'/'的根路由了,會報錯,/指定的根路由就多餘了
* 若是沒有home指定具體的頁面,那routes裏面就傲有/來指定根路由
* 路由的順序按照下面的規則來:
* 一、若是有home,就會從home進入
* 二、若是沒有home,有routes,而且routes指定了入口'/',就會從routes的/進入
* 三、若是上面兩個都沒有,或者路由趙達不到,若是有 onGenerateRoute,就會進入生成的路由
* 四、若是連上面的生成路由也沒有,就會走到onUnknownRoute,不明因此的路由,好比網絡鏈接失敗,能夠進入斷網的頁面
具體的用法看下下面的代碼
複製代碼
home: Home(),
佈局
final routes = {
'/Transform1': (BuildContext context) => new Transform1(),
'/Scale1': (BuildContext context) => new Scale1(),
'/Rotation1': (BuildContext context) => new Rotation1(),
'/': (BuildContext context) => new Home(),
};
...
在build裏面
routes: routes,
複製代碼
routes是一個對象,鍵是字符串,值是widgetbuilder,也就是widget 裏面包含了頁面的路由頁面配置。post
有下面的用法
onGenerateRoute: (RouteSettings settings) {
return new MaterialPageRoute<void>(
settings: settings,
builder: (BuildContext context) => Text('生成了路由'),
);
複製代碼
onGenerateRoute: (RouteSettings settings) {
return new MaterialPageRoute<void>(
settings: settings,
builder: (BuildContext context) => MaterialApp(
// routes: <String, WidgetBuilder>{
// '/': (context) => Text('用MaterialApp生成了新的路由')
// },
routes: routes,
),
);
},
複製代碼
onUnknownRoute: (RouteSettings settings) => MaterialPageRoute<void>(
settings: settings,
builder: (BuildContext context) => Text('路由找不到了')),
複製代碼
導航路由在跳轉時的回調,好比 push,pop,remove,replace是,能夠拿到當前路由和後面路由的信息。 route.settings.name能夠拿到路由的名字
navigatorObservers: <NavigatorObserver>[NewObserver()],
複製代碼
//導航的觀察者
//繼承NavigatorObserver
class NewObserver extends NavigatorObserver {
@override
void didPush(Route route, Route previousRoute) {
// 當調用Navigator.push時回調
super.didPush(route, previousRoute);
//可經過route.settings獲取路由相關內容
print(route.settings);
print(previousRoute);
}
@override
void didPop(Route route, Route previousRoute) {
// TODO: implement didPop
// 當調用Navigator.pop時回調
super.didPop(route, previousRoute);
print(route);
//route.currentResult獲取返回內容
print(previousRoute);
}
@override
void didRemove(Route route, Route previousRoute) {
// TODO: implement didRemove
// 當調用Navigator.Remove時回調
super.didRemove(route, previousRoute);
print(route);
print(previousRoute);
}
複製代碼
這個是直接渲染這個builder,不會走路由,優先渲染這個裏面的widget
builder: (BuildContext context, Widget w) => Text("生成新的view"),
複製代碼
設備用於識別用戶的應用程序的單行描述。在Android上,標題顯示在任務管理器的應用程序快照上方,當用戶按下「最近的應用程序」按鈕時會顯示這些快照。 在iOS上,沒法使用此值。 來自應用程序的Info.plist
的CFBundleDisplayName
在任什麼時候候都會被引用,不然就會引用CFBundleName
。要提供初始化的標題,能夠用 onGenerateTitle。
每次在WidgetsApp構建時都會從新生成
import 'dart:math';
...
Random a = Random(10);
...
在build的方法裏面
onGenerateTitle: (BuildContext context) =>
'${a.nextInt(100)}-隨機標題', //生成app的name,不能反回空,返回的是字符串
複製代碼
具體的用法以下
theme: new ThemeData(
primarySwatch: Colors.red, brightness: Brightness.light),
複製代碼
ThemeData單獨拿一篇文章來給你們演示,演示更直觀些。
默認值是false
顯示內容以下
CPU 15.5fps 60.7ms/frame
UI 0.5fps 2059.2ms/frame
複製代碼
默認值是false
默認值是false
默認值是false
默認值是false
默認值是false
多國的語言能夠查看 github.com/Lizhooh/flu…
static final List<Locale> supportedLocales = [
const Locale('en', 'US'),
const Locale('fi', 'FI'),
];
複製代碼
static final List<LocalizationsDelegate> localizationsDelegates = [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
];
複製代碼
static Locale localeResolutionCallback(
Locale locale, Iterable<Locale> supportedLocales) {
for (var supportedLocale in supportedLocales) {
if (supportedLocale.languageCode == locale.languageCode) {
return supportedLocale;
}
}
return supportedLocales.first;
}
複製代碼