1、无法加载http图片
找到这个地方加上这么一段话
标识让app可以使用明文通讯
android:usesCleartextTraffic="true"
2、加载本地图片
在根目录下创建一个放图片的目录
之后在配置图片路径
在界面中通过Image.asset("images/logo_200.png")
引用
3、 命名路由传值
注:一个app只能有一个MaterialApp 其他的地方要设置主题直接用Scaffold
跳转方式Navigator.pushNamed(context, '/search', arguments: {"id": 123});
class _MyTabberState extends State<MyTabber> {
final routes = {"/": (context) => Home(), '/search': (context, {arguments}) => SearchPage(arguments: arguments)};
@override
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: "/",
onGenerateRoute: (RouteSettings settings) {
//统一处理
final String name = settings.name;
final Function pageContentBuilder = this.routes[name];
if (pageContentBuilder != null) {
if (settings.arguments != null) {
final Route route = MaterialPageRoute(
builder: (context) =>
pageContentBuilder(context, arguments: settings.arguments),
);
return route;
} else {
final Route route = MaterialPageRoute(
builder: (context) => pageContentBuilder(context),
);
return route;
}
}
},
}
}
4、pub.dev中文网址
https://pub.flutter-io.cn/
第三方时间选择器flutter-cupertino-date-picker
5、flutter国际化
1、找到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;
});
}
6、关闭右上角debug图标
void main(List<String> args) {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: true, // true显示false相反
}
}
7、使用flutter-cupertino-date-picker遇到的问题
1、
解决方法DiagnosticableMixin
改成Diagnosticable
2、
找到这个注释掉