flutter 一切皆是组件,内置组件就是一个类
StatelessWidget: 是一个抽象类
项目中图片的使用:本地图片需要建立images/2.0x、3.0x .. 然后在pubspec.yuml中的assets引入
StatelessWidget是无状态组件,状态不可改变的widget
StatefulWidget是有状态组件,持有的状态可能在widget生命周期改变。改变页面的数据就可以使用
路由:
1、普通路由: Navigator.of(context).push(MaterialPageRoute(builder: (context) => Search())); 返回:Navigator.of(context).pop(); 传参和函数传参一致
2、命名路由:在根组件下:
return MaterialApp(home: Tabs(), routes: {
'/form': (context) => FormPage(),
'/': (context) => FormPage()
});
配置路由:
Navigator.of(Content).pushReplacementNamed(path) // 替换当前路由
Navigator.of(Content).pushAndRemoveUnitl(MaterialPageRoute(builder:(context) => new Tabs()), (route) => route == null) // 清空路由并返回到指定路由
TabBar也可以放在title的位置 appbar - title可以放任意的组件,可以将TabBar放在title的位置,实现头条的效果,appBar:AppBar(title:Row(children: <Widget>[Expanded(child:TabBar(.....
))]
From不能放在row容器里面 会报错
flutter showDatePicker showTimePicker显示中文日期
1、配置flutter_localizations依赖
找到pubspec.yaml配置flutter_localizations
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
2、导入国际化的包 flutter_localizations
import 'package:flutter_localizations/flutter_localizations.dart';
3、设置国际化
void main() {
runApp(
new MaterialApp(
title: 'app',
theme: new ThemeData(
primaryColor: Colors.white,
),
home: new MyLoginWidget(),
localizationsDelegates: [
//此处
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
//此处
const Locale('zh', 'CH'),
const Locale('en', 'US'),
],
),
);
}
4、要显示中文的控件设置:
_showDatePicker() async{
var date =await showDatePicker(
context: context,
initialDate: _datetime,
firstDate:DateTime(1900),
lastDate:DateTime(2050),
locale: Locale('zh'),
);
if(date==null) return;
print(date);
setState(() {
_datetime=date;
});
}
插件:用于访问位置信息GPS: geolocator; 相册和相机:image_picker; 本地存储:Shared Preference plugin; 访问数据:SQFile; 唤起第三方登录:flutter_facebook_login; 推送通知:firebase_messaging;图片缓存:cached_network_image;flutter-screenutil屏幕适配(首页,全局设置);持久化:shared_preferences
tips: singleChildScrollView标签,让页面具有滚动效果,就不会被吞没.
FutureBuilder();请求数据并很好的渲染
保持页面状态-使用with AutomaticKeepAliveClientMinxin在extends的时候
scrollController.jumpTo(0,0)