Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion lib/lang/app_translations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ class AppTranslations {
}

String t(String key) {
return _localisedValues[key] ?? "$key";
String finalReslut;
if (key.indexOf('.') >= 0) {
List langList = key.split('.');
Map tmpMap = _localisedValues;
for (final item in langList) {
if (tmpMap[item] != null) {
if (tmpMap[item] is String) {
finalReslut = tmpMap[item];
break;
} else {
tmpMap = tmpMap[item];
}
} else {
finalReslut = "$key";
break;
}
}
} else {
finalReslut = _localisedValues[key] ?? "$key";
}
return finalReslut;
}
}
63 changes: 63 additions & 0 deletions lib/page/home.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:flutter/material.dart';
import 'package:efox_flutter/lang/application.dart';
import 'package:efox_flutter/lang/app_translations.dart';
//
import 'package:efox_flutter/store/STORE.dart';

//
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
// 实例化语言包
AppTranslations lang = AppTranslations.of(context);
// 实例化model
// int age = STORE.get(context).userInfo.age;
return STORE.connect(builder: (context, child, model) {
return Scaffold(
appBar: AppBar(
title: Text(lang.t('title')),
actions: <Widget>[
PopupMenuButton(
icon: Icon(
Icons.more_vert,
color: Color(0xffffffff),
),
onSelected: (local) {
Application().onLocaleChanged(Locale(local));
print('local=$local');
},
itemBuilder: (context) => [
PopupMenuItem(
child: Row(
children: <Widget>[Text('中文')],
),
value: 'zh',
),
PopupMenuItem(
child: Row(
children: <Widget>[Text('english')],
),
value: 'en',
)
])
],
),
body: Center(
child: ExpansionTile(
title: Text(lang.t('widgetType.regularLayout')),
leading: Icon(Icons.account_balance_wallet),
backgroundColor: Colors.white12,
children: <Widget>[
ListTile(title: Text('list tile'), subtitle: Text('subtitle'))
],
initiallyExpanded: true,
)),
floatingActionButton: FloatingActionButton(
onPressed: model.setAge,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
});
}
}
Empty file.
2 changes: 1 addition & 1 deletion lib/router/index.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/widgets.dart';
//首页
import 'package:efox_flutter/page/home_page.dart';
import 'package:efox_flutter/page/home.dart';

//测试路由配置
import 'package:efox_flutter/router/test/index.dart';
Expand Down
57 changes: 57 additions & 0 deletions lib/store/json/widget_list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "widget list",
"list": [
{
"typeName": "regularLayout",
"widgetList": [
{
"name": "Row"
},
{
"name": "Column"
},
{
"name": "Container"
},
{
"name": "Center"
},
{
"name": "Padding"
},
{
"name": "Stack"
},
{
"name": "Expanded"
},
{
"name": "Align"
}
]
},
{
"typeName": "advancedLayout",
"widgetList": [
{
"name": "FittedBox"
},
{
"name": "ConstrainedBox"
},
{
"name": "DecoratedBox"
},
{
"name": "LimitedBox"
},
{
"name": "RotatedBox"
},
{
"name": "Table"
}
]
}
]
}
5 changes: 4 additions & 1 deletion locale/en.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"title": "efox flutter tech app"
"title": "efox flutter tech app",
"widgetType": {
"regularLayout": "common layout"
}
}
5 changes: 4 additions & 1 deletion locale/zh.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"title": "efox flutter教学应用"
"title": "efox flutter教学应用",
"widgetType": {
"regularLayout": "常规布局"
}
}