diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb new file mode 100644 index 0000000..5e41435 --- /dev/null +++ b/lib/l10n/intl_en.arb @@ -0,0 +1,4 @@ +{ + "appName": "Paas Dashboard", + "refresh": "Refresh" +} \ No newline at end of file diff --git a/lib/l10n/intl_zh.arb b/lib/l10n/intl_zh.arb new file mode 100644 index 0000000..a010c25 --- /dev/null +++ b/lib/l10n/intl_zh.arb @@ -0,0 +1,4 @@ +{ + "appName": "Paas 仪表盘", + "refresh": "刷新" +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index f757349..6b1e718 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,11 +1,15 @@ import 'package:flutter/material.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; +import 'package:paas_dashboard_flutter/generated/l10n.dart'; import 'package:paas_dashboard_flutter/module/pulsar/pulsar_topic.dart'; import 'package:paas_dashboard_flutter/route/page_route_const.dart'; import 'package:paas_dashboard_flutter/route/route_gen.dart'; import 'package:paas_dashboard_flutter/ui/bk/bk_page.dart'; +import 'package:paas_dashboard_flutter/ui/general/settings_screen.dart'; import 'package:paas_dashboard_flutter/ui/home/home_page.dart'; import 'package:paas_dashboard_flutter/ui/pulsar/pulsar_page.dart'; import 'package:paas_dashboard_flutter/vm/bk/bk_instance_list_view_model.dart'; +import 'package:paas_dashboard_flutter/vm/general/settings_view_model.dart'; import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_instance_list_view_model.dart'; import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_instance_view_model.dart'; import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_namespace_view_model.dart'; @@ -22,6 +26,13 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( title: 'Paas Dashboard', + localizationsDelegates: [ + S.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: S.delegate.supportedLocales, theme: ThemeData( // This is the theme of your application. // @@ -37,6 +48,10 @@ class MyApp extends StatelessWidget { initialRoute: PageRouteConst.Root, routes: { PageRouteConst.Root: (context) => HomePage(), + PageRouteConst.Settings: (context) => ChangeNotifierProvider( + create: (context) => SettingsViewModel(), + child: SettingsScreen(), + ), PageRouteConst.Bookkeeper: (context) => ChangeNotifierProvider( create: (context) => BkInstanceListViewModel(), child: BkPage(), diff --git a/lib/route/page_route_const.dart b/lib/route/page_route_const.dart index 5332847..89a86d1 100644 --- a/lib/route/page_route_const.dart +++ b/lib/route/page_route_const.dart @@ -1,5 +1,6 @@ class PageRouteConst { static const String Root = '/'; + static const String Settings = '/settings'; static const String Bookkeeper = '/bookkeeper'; static const String Pulsar = '/pulsar'; static const String PulsarInstance = '/pulsar/instance'; diff --git a/lib/ui/general/settings_screen.dart b/lib/ui/general/settings_screen.dart new file mode 100644 index 0000000..39c8ca1 --- /dev/null +++ b/lib/ui/general/settings_screen.dart @@ -0,0 +1,63 @@ +import 'dart:developer'; + +import 'package:flutter/material.dart'; +import 'package:paas_dashboard_flutter/vm/general/settings_view_model.dart'; +import 'package:provider/provider.dart'; + +class SettingsScreen extends StatefulWidget { + SettingsScreen(); + + @override + State createState() { + return new SettingsScreenState(); + } +} + +class SettingsScreenState extends State { + @override + void initState() { + super.initState(); + } + + @override + void dispose() { + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final vm = Provider.of(context); + return Scaffold( + appBar: AppBar( + title: Text('Settings'), + ), + body: ExpansionTile( + title: Text('Change language'), + leading: Icon(Icons.language), + initiallyExpanded: false, + children: [ + RadioListTile( + title: Text('English'), + value: 'en', + groupValue: vm.language, + onChanged: _changed), + RadioListTile( + title: Text('汉语'), + value: 'zh', + groupValue: vm.language, + onChanged: _changed), + ], + ), + ); + } + + void _changed(value) { + if (value != null) { + log('change language to $value'); + final vm = Provider.of(context, listen: false); + if (value != null) { + vm.setLan(value); + } + } + } +} diff --git a/lib/ui/home/home_drawer.dart b/lib/ui/home/home_drawer.dart index bce2090..e4489a1 100644 --- a/lib/ui/home/home_drawer.dart +++ b/lib/ui/home/home_drawer.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:paas_dashboard_flutter/route/page_route_const.dart'; class NavDrawer extends StatelessWidget { @override @@ -23,6 +24,11 @@ class NavDrawer extends StatelessWidget { title: Text('About author'), onTap: () => {Navigator.of(context).pop()}, ), + ListTile( + title: Text('Settings'), + onTap: () => + {Navigator.of(context).pushNamed(PageRouteConst.Settings)}, + ), ], ), ); diff --git a/lib/ui/pulsar/pulsar_page.dart b/lib/ui/pulsar/pulsar_page.dart index a072bc7..4d7f368 100644 --- a/lib/ui/pulsar/pulsar_page.dart +++ b/lib/ui/pulsar/pulsar_page.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:paas_dashboard_flutter/generated/l10n.dart'; import 'package:paas_dashboard_flutter/route/page_route_const.dart'; import 'package:paas_dashboard_flutter/ui/util/form_util.dart'; import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_instance_list_view_model.dart'; @@ -59,7 +60,7 @@ class _PulsarPageState extends State { onPressed: () { vm.fetchPulsarInstances(); }, - child: Text('Refresh')); + child: Text(S.of(context).refresh)); var body = ListView( children: [ Container( diff --git a/lib/vm/general/settings_view_model.dart b/lib/vm/general/settings_view_model.dart new file mode 100644 index 0000000..1d2bf20 --- /dev/null +++ b/lib/vm/general/settings_view_model.dart @@ -0,0 +1,10 @@ +import 'package:flutter/material.dart'; + +class SettingsViewModel extends ChangeNotifier { + String language = 'en'; + + void setLan(String lan) { + this.language = lan; + notifyListeners(); + } +} diff --git a/pubspec.lock b/pubspec.lock index 2f3f5fe..6e0cbdc 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -69,6 +69,11 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_localizations: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" flutter_test: dependency: "direct dev" description: flutter @@ -88,6 +93,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "4.0.0" + intl: + dependency: transitive + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.17.0" matcher: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 6e65f1a..96f8409 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -33,6 +33,8 @@ dependencies: sqflite: sqflite_common_ffi: path: + flutter_localizations: + sdk: flutter dev_dependencies: flutter_test: @@ -81,3 +83,5 @@ flutter: # # For details regarding fonts from package dependencies, # see https://flutter.dev/custom-fonts/#from-packages +flutter_intl: + enabled: true