From d18ffe52f7e205bc62c10730aa508ba3ee90b6c3 Mon Sep 17 00:00:00 2001 From: hanandjun Date: Tue, 3 Nov 2020 21:05:27 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9C=80=E8=A6=81=E7=BF=BB=E8=AF=91=E7=9A=84?= =?UTF-8?q?=E6=9C=89=E4=BA=9B=E5=A4=9A=EF=BC=8C=E6=85=A2=E6=85=A2=E6=9D=A5?= =?UTF-8?q?=E5=90=A7.=E5=85=88=E8=BF=99=E6=A0=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/generated/intl/messages_en.dart | 8 +++ lib/generated/intl/messages_ja.dart | 8 +++ lib/generated/intl/messages_zh.dart | 8 +++ lib/generated/l10n.dart | 80 +++++++++++++++++++++++++ lib/l10n/intl_en.arb | 8 +++ lib/l10n/intl_ja.arb | 8 +++ lib/l10n/intl_zh.arb | 8 +++ lib/util/language_util.dart | 5 +- lib/view/app.dart | 10 +--- lib/view/home.dart | 4 +- lib/view/home/home_page.dart | 49 +++++++-------- lib/view/home/news/news_list.dart | 2 +- lib/view/home/searchbar/search_bar.dart | 3 +- lib/view/more/settings/settings.dart | 4 -- lib/view/store/locale_provider.dart | 1 - lib/view/store/news_model.dart | 4 +- 16 files changed, 165 insertions(+), 45 deletions(-) diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index f83e5c6..cff09fb 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -22,9 +22,17 @@ class MessageLookup extends MessageLookupByLibrary { final messages = _notInlinedMessages(_notInlinedMessages); static _notInlinedMessages(_) => { "AppName" : MessageLookupByLibrary.simpleMessage("WeiFang Bus"), + "ExitApp" : MessageLookupByLibrary.simpleMessage("click again to exit the application"), + "Explore" : MessageLookupByLibrary.simpleMessage("Explore"), + "Guide" : MessageLookupByLibrary.simpleMessage("Guide"), "Home" : MessageLookupByLibrary.simpleMessage("Home"), "LanguageSettings" : MessageLookupByLibrary.simpleMessage("Language Settings"), "More" : MessageLookupByLibrary.simpleMessage("More"), + "News" : MessageLookupByLibrary.simpleMessage("News"), + "NoNews" : MessageLookupByLibrary.simpleMessage("No News"), + "NoPictures" : MessageLookupByLibrary.simpleMessage("No Pictures"), + "RouteQuery" : MessageLookupByLibrary.simpleMessage("Route Query"), + "SearchLine" : MessageLookupByLibrary.simpleMessage("Search Line"), "Settings" : MessageLookupByLibrary.simpleMessage("Settings") }; } diff --git a/lib/generated/intl/messages_ja.dart b/lib/generated/intl/messages_ja.dart index 2831ff9..2487ec2 100644 --- a/lib/generated/intl/messages_ja.dart +++ b/lib/generated/intl/messages_ja.dart @@ -22,9 +22,17 @@ class MessageLookup extends MessageLookupByLibrary { final messages = _notInlinedMessages(_notInlinedMessages); static _notInlinedMessages(_) => { "AppName" : MessageLookupByLibrary.simpleMessage("潍坊 バス"), + "ExitApp" : MessageLookupByLibrary.simpleMessage("もう一度クリックしてアプリを終了します"), + "Explore" : MessageLookupByLibrary.simpleMessage("見る"), + "Guide" : MessageLookupByLibrary.simpleMessage("ガイド"), "Home" : MessageLookupByLibrary.simpleMessage("ホーム"), "LanguageSettings" : MessageLookupByLibrary.simpleMessage("言語設定"), "More" : MessageLookupByLibrary.simpleMessage("もっと"), + "News" : MessageLookupByLibrary.simpleMessage("ニュース"), + "NoNews" : MessageLookupByLibrary.simpleMessage("情報はまだありません"), + "NoPictures" : MessageLookupByLibrary.simpleMessage("写真はしばらくありません"), + "RouteQuery" : MessageLookupByLibrary.simpleMessage("ルートクエリ"), + "SearchLine" : MessageLookupByLibrary.simpleMessage("経路を探索する"), "Settings" : MessageLookupByLibrary.simpleMessage("セットアップ") }; } diff --git a/lib/generated/intl/messages_zh.dart b/lib/generated/intl/messages_zh.dart index 6b16469..2716502 100644 --- a/lib/generated/intl/messages_zh.dart +++ b/lib/generated/intl/messages_zh.dart @@ -22,9 +22,17 @@ class MessageLookup extends MessageLookupByLibrary { final messages = _notInlinedMessages(_notInlinedMessages); static _notInlinedMessages(_) => { "AppName" : MessageLookupByLibrary.simpleMessage("潍坊公交"), + "ExitApp" : MessageLookupByLibrary.simpleMessage("再次点击退出应用"), + "Explore" : MessageLookupByLibrary.simpleMessage("探索"), + "Guide" : MessageLookupByLibrary.simpleMessage("导 乘"), "Home" : MessageLookupByLibrary.simpleMessage("首页"), "LanguageSettings" : MessageLookupByLibrary.simpleMessage("语言设置"), "More" : MessageLookupByLibrary.simpleMessage("更多"), + "News" : MessageLookupByLibrary.simpleMessage("资 讯"), + "NoNews" : MessageLookupByLibrary.simpleMessage("暂无资讯信息"), + "NoPictures" : MessageLookupByLibrary.simpleMessage("暂无图片展示"), + "RouteQuery" : MessageLookupByLibrary.simpleMessage("线路查询"), + "SearchLine" : MessageLookupByLibrary.simpleMessage("搜索线路"), "Settings" : MessageLookupByLibrary.simpleMessage("设置") }; } diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 8f8619d..7f2e20c 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -55,6 +55,16 @@ class S { ); } + /// `Explore` + String get Explore { + return Intl.message( + 'Explore', + name: 'Explore', + desc: '', + args: [], + ); + } + /// `More` String get More { return Intl.message( @@ -65,6 +75,76 @@ class S { ); } + /// `click again to exit the application` + String get ExitApp { + return Intl.message( + 'click again to exit the application', + name: 'ExitApp', + desc: '', + args: [], + ); + } + + /// `Route Query` + String get RouteQuery { + return Intl.message( + 'Route Query', + name: 'RouteQuery', + desc: '', + args: [], + ); + } + + /// `Guide` + String get Guide { + return Intl.message( + 'Guide', + name: 'Guide', + desc: '', + args: [], + ); + } + + /// `News` + String get News { + return Intl.message( + 'News', + name: 'News', + desc: '', + args: [], + ); + } + + /// `No News` + String get NoNews { + return Intl.message( + 'No News', + name: 'NoNews', + desc: '', + args: [], + ); + } + + /// `No Pictures` + String get NoPictures { + return Intl.message( + 'No Pictures', + name: 'NoPictures', + desc: '', + args: [], + ); + } + + /// `Search Line` + String get SearchLine { + return Intl.message( + 'Search Line', + name: 'SearchLine', + desc: '', + args: [], + ); + } + /// `Settings` String get Settings { return Intl.message( diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index b08857a..06a0d2f 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -1,7 +1,15 @@ { "AppName": "WeiFang Bus", "Home": "Home", + "Explore": "Explore", "More": "More", + "ExitApp": "click again to exit the application", + "RouteQuery": "Route Query", + "Guide": "Guide", + "News": "News", + "NoNews": "No News", + "NoPictures": "No Pictures", + "SearchLine": "Search Line", "Settings": "Settings", "LanguageSettings": "Language Settings" } diff --git a/lib/l10n/intl_ja.arb b/lib/l10n/intl_ja.arb index b085cfb..c30dae7 100644 --- a/lib/l10n/intl_ja.arb +++ b/lib/l10n/intl_ja.arb @@ -1,7 +1,15 @@ { "AppName": "潍坊 バス", "Home": "ホーム", + "Explore": "見る", "More": "もっと", + "ExitApp": "もう一度クリックしてアプリを終了します", + "RouteQuery": "ルートクエリ", + "Guide": "ガイド", + "News": "ニュース", + "NoNews": "情報はまだありません", + "NoPictures": "写真はしばらくありません", + "SearchLine": "経路を探索する", "Settings": "セットアップ", "LanguageSettings": "言語設定" } diff --git a/lib/l10n/intl_zh.arb b/lib/l10n/intl_zh.arb index 79893e9..81aab86 100644 --- a/lib/l10n/intl_zh.arb +++ b/lib/l10n/intl_zh.arb @@ -1,7 +1,15 @@ { "AppName": "潍坊公交", "Home": "首页", + "Explore": "探索", "More": "更多", + "ExitApp": "再次点击退出应用", + "RouteQuery": "线路查询", + "Guide": "导 乘", + "News": "资 讯", + "NoNews": "暂无资讯信息", + "NoPictures": "暂无图片展示", + "SearchLine": "搜索线路", "Settings": "设置", "LanguageSettings": "语言设置" } diff --git a/lib/util/language_util.dart b/lib/util/language_util.dart index cf1810a..adff762 100644 --- a/lib/util/language_util.dart +++ b/lib/util/language_util.dart @@ -44,10 +44,11 @@ class LanguageUtil { return str; } - /// 展示和设置语言 + /// 设置语言 static setLanguage( BuildContext context, LanguagePreference languagePreference) { - print('语言切换至: $languagePreference'); + var str = languageString(languagePreference); + print('语言切换至: $str'); switch (languagePreference) { case LanguagePreference.auto: context.read().setLocale(null); diff --git a/lib/view/app.dart b/lib/view/app.dart index 1b70035..c090797 100644 --- a/lib/view/app.dart +++ b/lib/view/app.dart @@ -27,20 +27,15 @@ class _WeiFangBusApp extends State { Locale _locale; /// 获取选择的外观 - _getAppearance() async { + _getAppearanceAndLanguage() async { var appearance = await AppearanceUtil.getAppearance(); - print('appearance: $appearance'); var languagePreference = await LanguageUtil.getLanguagePreference(); - print('languagePreference: $languagePreference'); var locale = LanguageUtil.getLocale(languagePreference); - print('locale: $locale _locale: $_locale'); setState(() { - print('app 设置语言'); _locale = locale; }); if (appearance != null && _appearance != appearance) { setState(() { - print('app 设置外观'); _appearance = appearance; }); } @@ -65,12 +60,11 @@ class _WeiFangBusApp extends State { super.initState(); // 强制竖屏 SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); - _getAppearance(); + _getAppearanceAndLanguage(); } @override Widget build(BuildContext context) { - print('app 开始构建'); return MultiProvider( providers: [ // 资讯信息 diff --git a/lib/view/home.dart b/lib/view/home.dart index 8a96897..b6ae54c 100644 --- a/lib/view/home.dart +++ b/lib/view/home.dart @@ -66,7 +66,7 @@ class _HomeState extends State with SingleTickerProviderStateMixin { ), BottomNavigationBarItem( icon: Icon(Icons.explore), - label: '发现', + label: S.of(context).Explore, ), BottomNavigationBarItem( icon: Icon(Icons.more_vert), @@ -95,7 +95,7 @@ class _HomeState extends State with SingleTickerProviderStateMixin { _homeKey.currentState.showSnackBar( SnackBar( content: Text( - '再次点击退出应用', + S.of(context).ExitApp, textAlign: TextAlign.center, ), duration: Duration(milliseconds: 1500), diff --git a/lib/view/home/home_page.dart b/lib/view/home/home_page.dart index 0f61231..1054650 100644 --- a/lib/view/home/home_page.dart +++ b/lib/view/home/home_page.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:auto_size_text/auto_size_text.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:connectivity/connectivity.dart'; import 'package:dio/dio.dart'; @@ -13,6 +14,7 @@ import 'package:weifangbus/entity/headline_entity.dart'; import 'package:weifangbus/entity/menu_entity.dart'; import 'package:weifangbus/entity/startup_basic_info_entity.dart'; import 'package:weifangbus/entity_factory.dart'; +import 'package:weifangbus/generated/l10n.dart'; import 'package:weifangbus/util/dio_util.dart'; import 'package:weifangbus/util/font_util.dart'; import 'package:weifangbus/util/request_params_util.dart'; @@ -32,9 +34,6 @@ class HomePage extends StatefulWidget { class _HomePageState extends State with AutomaticKeepAliveClientMixin { - /// 菜单项 - List _menuEntityList = List(); - /// 初始页json数据实体类 Future _startUpBasicInfoFuture; @@ -56,9 +55,7 @@ class _HomePageState extends State @override void initState() { super.initState(); - setMenuEntityList(); _startUpBasicInfoFuture = _getStartUpBasicInfoFuture(); - // getAllRoute(); } @override @@ -75,11 +72,12 @@ class _HomePageState extends State } /// 设置菜单 - void setMenuEntityList() { + setMenuEntityList() { + List menuEntityList = List(); MenuEntity lineInquiry = MenuEntity( Colors.lightGreen, MyIcons.lineInquiry, - "线路查询", + S.of(context).RouteQuery, () { Navigator.push( context, @@ -88,7 +86,7 @@ class _HomePageState extends State return Material( child: MaterialSearch( barBackgroundColor: Theme.of(context).primaryColor, - placeholder: "搜索线路", + placeholder: S.of(context).SearchLine, results: _allRouteList, filter: (dynamic value, String criteria) { return value.toLowerCase().trim().contains( @@ -101,11 +99,11 @@ class _HomePageState extends State ); }, ); - _menuEntityList.add(lineInquiry); + menuEntityList.add(lineInquiry); MenuEntity guide = MenuEntity( Colors.lightBlue, MyIcons.guide, - '导乘', + S.of(context).Guide, () { Navigator.push( context, @@ -117,11 +115,11 @@ class _HomePageState extends State ); }, ); - _menuEntityList.add(guide); + menuEntityList.add(guide); MenuEntity news = MenuEntity( Colors.orangeAccent, MyIcons.news, - '资讯', + S.of(context).News, () { Navigator.push( context, @@ -133,7 +131,8 @@ class _HomePageState extends State ); }, ); - _menuEntityList.add(news); + menuEntityList.add(news); + return menuEntityList; } /// 请求首页数据 @@ -147,7 +146,7 @@ class _HomePageState extends State Response response = await dio.get(uri); var startUpBasicInfoEntity = EntityFactory.generateOBJ(response.data); - print("请求轮播图完毕"); + print("请求 轮播图 完毕"); if (startUpBasicInfoEntity == null) { startUpBasicInfoEntity = StartUpBasicInfoEntity(); } @@ -171,7 +170,7 @@ class _HomePageState extends State response = await dio.get(uri); AllroutedataEntity allRouteDataEntity = EntityFactory.generateOBJ(response.data); - print("请求全部线路完成"); + print("请求 线路信息 完毕"); var routeList = allRouteDataEntity.routelist; List> materialSearchResultList = List(); for (var i = 0; i < routeList.length; ++i) { @@ -279,8 +278,8 @@ class _HomePageState extends State color: Colors.deepOrangeAccent, ), child: Padding( - child: Text( - "资\n讯", + child: AutoSizeText( + S.of(context).News, style: TextStyle( color: Colors.white, ), @@ -311,7 +310,7 @@ class _HomePageState extends State fontSize: 44.ssp, ), ) - : Text('暂无资讯信息'), + : Text(S.of(context).NoNews), ), ], ); @@ -385,13 +384,15 @@ class _HomePageState extends State autoplayDelay: 4000, ) : Center( - child: Text('暂无图片展示'), + child: Text(S.of(context).NoPictures), ), ); } /// 菜单项 Widget menuWidget() { + /// 菜单项 + List menuEntityList = setMenuEntityList(); return SliverPadding( padding: EdgeInsets.all(10.w), sliver: SliverGrid( @@ -414,7 +415,7 @@ class _HomePageState extends State height: 180.h, child: DecoratedBox( decoration: BoxDecoration( - color: _menuEntityList[index].color, + color: menuEntityList[index].color, shape: BoxShape.circle, boxShadow: [ BoxShadow( @@ -428,7 +429,7 @@ class _HomePageState extends State ), child: Center( child: Icon( - _menuEntityList[index].icon, + menuEntityList[index].icon, size: 80.w, color: Colors.white, ), @@ -440,7 +441,7 @@ class _HomePageState extends State top: 25.h, ), child: Text( - _menuEntityList[index].menuText, + menuEntityList[index].menuText, style: TextStyle( fontSize: 40.ssp, ), @@ -449,10 +450,10 @@ class _HomePageState extends State ], ), ), - onTap: _menuEntityList[index].function, + onTap: menuEntityList[index].function, ); }, - childCount: _menuEntityList.length, + childCount: menuEntityList.length, ), ), ); diff --git a/lib/view/home/news/news_list.dart b/lib/view/home/news/news_list.dart index caa90ae..c477bd0 100644 --- a/lib/view/home/news/news_list.dart +++ b/lib/view/home/news/news_list.dart @@ -93,7 +93,7 @@ class _NewsListPageState extends State { context.read().refreshNewsList(); showSnackBar('刷新成功!'); } catch (e) { - print('刷新资讯列表出错::: $e'); + print('刷新资讯信息出错::: $e'); showSnackBar('请求数据失败,请尝试切换网络后重试!'); } } else { diff --git a/lib/view/home/searchbar/search_bar.dart b/lib/view/home/searchbar/search_bar.dart index 524795b..d59a113 100644 --- a/lib/view/home/searchbar/search_bar.dart +++ b/lib/view/home/searchbar/search_bar.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:weifangbus/generated/l10n.dart'; import 'package:weifangbus/view/home/searchbar/search_input.dart'; /// 搜索栏 @@ -36,7 +37,7 @@ class _SearchBarState extends State { ), Expanded( child: MaterialSearchInput( - placeholder: "搜索线路", + placeholder: S.of(context).SearchLine, results: widget.allRouteList, filter: (dynamic value, String criteria) { return value.toLowerCase().trim().contains( diff --git a/lib/view/more/settings/settings.dart b/lib/view/more/settings/settings.dart index 5019c44..6fe976e 100644 --- a/lib/view/more/settings/settings.dart +++ b/lib/view/more/settings/settings.dart @@ -24,10 +24,8 @@ class _SettingsState extends State { @override Widget build(BuildContext context) { - print('开始构建'); var appearance = context.watch().appearance; var locale = context.watch().locale; - print('locale: $locale'); if (locale != null) { var languagePreference = LanguageUtil.getLanguage(locale); if (languagePreference != null) { @@ -94,7 +92,6 @@ class _SettingsState extends State { /// 获取外观和语言 _getAppearance() async { var appearance = await AppearanceUtil.getAppearance(); - print('appearance: $appearance'); setState(() { _appearance = appearance; }); @@ -102,7 +99,6 @@ class _SettingsState extends State { _getLanguage() async { var languagePreference = await LanguageUtil.getLanguagePreference(); - print('languagePreference: $languagePreference'); setState(() { _languagePreference = languagePreference; }); diff --git a/lib/view/store/locale_provider.dart b/lib/view/store/locale_provider.dart index 149c1e6..fe4fb06 100644 --- a/lib/view/store/locale_provider.dart +++ b/lib/view/store/locale_provider.dart @@ -10,7 +10,6 @@ class LocaleProvider extends ChangeNotifier { Locale get locale => _locale; setLocale(Locale locale) { - print('设置语言: $locale'); manuallyChangeLanguage = true; _locale = locale; notifyListeners(); diff --git a/lib/view/store/news_model.dart b/lib/view/store/news_model.dart index 19267bd..fd592f8 100644 --- a/lib/view/store/news_model.dart +++ b/lib/view/store/news_model.dart @@ -30,11 +30,11 @@ class NewsModel with ChangeNotifier { List newsList = list .map((dynamic) => EntityFactory.generateOBJ(dynamic)) .toList(); - print('请求资讯列表数据完毕'); + print('请求 资讯信息 完毕'); newsList ?? List(); return newsList; } on DioError catch (e) { - print(getErrorMsg(e, msg: "请求资讯列表数据")); + print(getErrorMsg(e, msg: "请求 资讯信息")); return Future.error(e); } }