flutter_easyrefresh 1.0.8 flutter_easyrefresh: ^1.0.8 copied to clipboard
A widget provided to the flutter scroll component drop-down refresh and pull up load.
import 'package:example/generated/application.dart';
import 'package:example/generated/translations.dart';
import 'package:example/page/home_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
SpecificLocalizationDelegate _localeOverrideDelegate;
@override
void initState(){
super.initState();
/// 初始化一个新的Localization Delegate,有了它,当用户选择一种新的工作语言时,可以强制初始化一个新的Translations
_localeOverrideDelegate = new SpecificLocalizationDelegate(null);
/// 保存这个方法的指针,当用户改变语言时,我们可以调用applic.onLocaleChanged(new Locale('en',''));,通过SetState()我们可以强制App整个刷新
applic.onLocaleChanged = onLocaleChange;
}
/// 改变语言时的应用刷新核心,每次选择一种新的语言时,都会创造一个新的SpecificLocalizationDelegate实例,强制Translations类刷新。
onLocaleChange(Locale locale){
setState((){
_localeOverrideDelegate = new SpecificLocalizationDelegate(locale);
});
}
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
// App名字
title: 'Flutter Demo',
// App主题
theme: new ThemeData(
primarySwatch: Colors.orange,
),
// 主页
home: HomePage(),
// 路由
routes: <String, WidgetBuilder> {
'/home': (BuildContext context) => HomePage()
},
localizationsDelegates: [
_localeOverrideDelegate, // 注册一个新的delegate
const TranslationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
supportedLocales: applic.supportedLocales(),
);
}
}