示例 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;
}
复制代码