Skip to content

Commit b1883bc

Browse files
committed
feature:update widget system parser
1 parent 417b13b commit b1883bc

File tree

824 files changed

+9590
-4879
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

824 files changed

+9590
-4879
lines changed

analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ linter:
1616

1717
analyzer:
1818
exclude:
19-
- modules/widget_system/widgets/**
19+
# - modules/widget_system/widgets/**
2020

2121

2222

assets/flutter.db

84 KB
Binary file not shown.

desiredFileName.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

l10n.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
arb-dir: lib/src/l10n/arb
2+
template-arb-file: app_zh.arb
3+
output-localization-file: app_l10n.dart
4+
5+
6+
synthetic-package: false
7+
output-dir: lib/src/l10n/gen
8+
output-class: AppL10n
9+
nullable-getter: false
10+
untranslated-messages-file: desiredFileName.txt

lib/src/flutter_unit.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import 'package:app/app.dart';
22
import 'package:flutter/material.dart';
33
import 'package:flutter_bloc/flutter_bloc.dart';
4+
import 'package:flutter_localizations/flutter_localizations.dart';
45

56
import 'package:go_router/go_router.dart';
7+
import 'package:l10n/gen_l10n/app_localizations.dart';
68
import 'package:l10n/l10n.dart';
79
import 'package:tolyui/tolyui.dart';
810

11+
import 'l10n/gen/app_l10n.dart';
912
import 'navigation/router/app_route.dart';
1013

1114
/// create by 张风捷特烈 on 2020/4/28
@@ -37,7 +40,13 @@ class FlutterUnit3 extends StatelessWidget {
3740
showPerformanceOverlay: state.showPerformanceOverlay,
3841
title: StrUnit.appName,
3942
debugShowCheckedModeBanner: false,
40-
localizationsDelegates: l10nDelegates,
43+
localizationsDelegates: const [
44+
AppL10n.delegate,
45+
AppLocalizations.delegate,
46+
GlobalMaterialLocalizations.delegate,
47+
GlobalCupertinoLocalizations.delegate,
48+
GlobalWidgetsLocalizations.delegate,
49+
],
4150
supportedLocales: l10nLocales,
4251
locale: state.language.locale,
4352
themeMode: state.themeMode,

lib/src/l10n/arb/app_en.arb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"deskTabWidgets": "Widgets",
3+
"deskTabPainter": "Painter",
4+
"deskTabKnowledge": "Knowledge",
5+
"deskTabTools": "Treasure",
6+
"deskTabMine": "About",
7+
8+
"mobileTabWidgets": "Widgets",
9+
"mobileTabPainter": "Painter",
10+
"mobileTabKnowledge": "Knowledge",
11+
"mobileTabTools": "Treasure",
12+
"mobileTabMine": "Mine"
13+
}

lib/src/l10n/arb/app_zh.arb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"deskTabWidgets": "组件集录",
3+
"deskTabPainter": "绘制集录",
4+
"deskTabKnowledge": "知识集锦",
5+
"deskTabTools": "工具宝箱",
6+
"deskTabMine": "应用信息",
7+
8+
"mobileTabWidgets": "组件",
9+
"mobileTabPainter": "绘制",
10+
"mobileTabKnowledge": "知识",
11+
"mobileTabTools": "工具",
12+
"mobileTabMine": "我的"
13+
}

lib/src/l10n/gen/app_l10n.dart

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
import 'dart:async';
2+
3+
import 'package:flutter/foundation.dart';
4+
import 'package:flutter/widgets.dart';
5+
import 'package:flutter_localizations/flutter_localizations.dart';
6+
import 'package:intl/intl.dart' as intl;
7+
8+
import 'app_l10n_en.dart';
9+
import 'app_l10n_zh.dart';
10+
11+
// ignore_for_file: type=lint
12+
13+
/// Callers can lookup localized strings with an instance of AppL10n
14+
/// returned by `AppL10n.of(context)`.
15+
///
16+
/// Applications need to include `AppL10n.delegate()` in their app's
17+
/// `localizationDelegates` list, and the locales they support in the app's
18+
/// `supportedLocales` list. For example:
19+
///
20+
/// ```dart
21+
/// import 'gen/app_l10n.dart';
22+
///
23+
/// return MaterialApp(
24+
/// localizationsDelegates: AppL10n.localizationsDelegates,
25+
/// supportedLocales: AppL10n.supportedLocales,
26+
/// home: MyApplicationHome(),
27+
/// );
28+
/// ```
29+
///
30+
/// ## Update pubspec.yaml
31+
///
32+
/// Please make sure to update your pubspec.yaml to include the following
33+
/// packages:
34+
///
35+
/// ```yaml
36+
/// dependencies:
37+
/// # Internationalization support.
38+
/// flutter_localizations:
39+
/// sdk: flutter
40+
/// intl: any # Use the pinned version from flutter_localizations
41+
///
42+
/// # Rest of dependencies
43+
/// ```
44+
///
45+
/// ## iOS Applications
46+
///
47+
/// iOS applications define key application metadata, including supported
48+
/// locales, in an Info.plist file that is built into the application bundle.
49+
/// To configure the locales supported by your app, you’ll need to edit this
50+
/// file.
51+
///
52+
/// First, open your project’s ios/Runner.xcworkspace Xcode workspace file.
53+
/// Then, in the Project Navigator, open the Info.plist file under the Runner
54+
/// project’s Runner folder.
55+
///
56+
/// Next, select the Information Property List item, select Add Item from the
57+
/// Editor menu, then select Localizations from the pop-up menu.
58+
///
59+
/// Select and expand the newly-created Localizations item then, for each
60+
/// locale your application supports, add a new item and select the locale
61+
/// you wish to add from the pop-up menu in the Value field. This list should
62+
/// be consistent with the languages listed in the AppL10n.supportedLocales
63+
/// property.
64+
abstract class AppL10n {
65+
AppL10n(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString());
66+
67+
final String localeName;
68+
69+
static AppL10n of(BuildContext context) {
70+
return Localizations.of<AppL10n>(context, AppL10n)!;
71+
}
72+
73+
static const LocalizationsDelegate<AppL10n> delegate = _AppL10nDelegate();
74+
75+
/// A list of this localizations delegate along with the default localizations
76+
/// delegates.
77+
///
78+
/// Returns a list of localizations delegates containing this delegate along with
79+
/// GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate,
80+
/// and GlobalWidgetsLocalizations.delegate.
81+
///
82+
/// Additional delegates can be added by appending to this list in
83+
/// MaterialApp. This list does not have to be used at all if a custom list
84+
/// of delegates is preferred or required.
85+
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates = <LocalizationsDelegate<dynamic>>[
86+
delegate,
87+
GlobalMaterialLocalizations.delegate,
88+
GlobalCupertinoLocalizations.delegate,
89+
GlobalWidgetsLocalizations.delegate,
90+
];
91+
92+
/// A list of this localizations delegate's supported locales.
93+
static const List<Locale> supportedLocales = <Locale>[
94+
Locale('en'),
95+
Locale('zh')
96+
];
97+
98+
/// No description provided for @deskTabWidgets.
99+
///
100+
/// In zh, this message translates to:
101+
/// **'组件集录'**
102+
String get deskTabWidgets;
103+
104+
/// No description provided for @deskTabPainter.
105+
///
106+
/// In zh, this message translates to:
107+
/// **'绘制集录'**
108+
String get deskTabPainter;
109+
110+
/// No description provided for @deskTabKnowledge.
111+
///
112+
/// In zh, this message translates to:
113+
/// **'知识集锦'**
114+
String get deskTabKnowledge;
115+
116+
/// No description provided for @deskTabTools.
117+
///
118+
/// In zh, this message translates to:
119+
/// **'工具宝箱'**
120+
String get deskTabTools;
121+
122+
/// No description provided for @deskTabMine.
123+
///
124+
/// In zh, this message translates to:
125+
/// **'应用信息'**
126+
String get deskTabMine;
127+
128+
/// No description provided for @mobileTabWidgets.
129+
///
130+
/// In zh, this message translates to:
131+
/// **'组件'**
132+
String get mobileTabWidgets;
133+
134+
/// No description provided for @mobileTabPainter.
135+
///
136+
/// In zh, this message translates to:
137+
/// **'绘制'**
138+
String get mobileTabPainter;
139+
140+
/// No description provided for @mobileTabKnowledge.
141+
///
142+
/// In zh, this message translates to:
143+
/// **'知识'**
144+
String get mobileTabKnowledge;
145+
146+
/// No description provided for @mobileTabTools.
147+
///
148+
/// In zh, this message translates to:
149+
/// **'工具'**
150+
String get mobileTabTools;
151+
152+
/// No description provided for @mobileTabMine.
153+
///
154+
/// In zh, this message translates to:
155+
/// **'我的'**
156+
String get mobileTabMine;
157+
}
158+
159+
class _AppL10nDelegate extends LocalizationsDelegate<AppL10n> {
160+
const _AppL10nDelegate();
161+
162+
@override
163+
Future<AppL10n> load(Locale locale) {
164+
return SynchronousFuture<AppL10n>(lookupAppL10n(locale));
165+
}
166+
167+
@override
168+
bool isSupported(Locale locale) => <String>['en', 'zh'].contains(locale.languageCode);
169+
170+
@override
171+
bool shouldReload(_AppL10nDelegate old) => false;
172+
}
173+
174+
AppL10n lookupAppL10n(Locale locale) {
175+
176+
177+
// Lookup logic when only language code is specified.
178+
switch (locale.languageCode) {
179+
case 'en': return AppL10nEn();
180+
case 'zh': return AppL10nZh();
181+
}
182+
183+
throw FlutterError(
184+
'AppL10n.delegate failed to load unsupported locale "$locale". This is likely '
185+
'an issue with the localizations generation tool. Please file an issue '
186+
'on GitHub with a reproducible sample app and the gen-l10n configuration '
187+
'that was used.'
188+
);
189+
}

lib/src/l10n/gen/app_l10n_en.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import 'app_l10n.dart';
2+
3+
// ignore_for_file: type=lint
4+
5+
/// The translations for English (`en`).
6+
class AppL10nEn extends AppL10n {
7+
AppL10nEn([String locale = 'en']) : super(locale);
8+
9+
@override
10+
String get deskTabWidgets => 'Widgets';
11+
12+
@override
13+
String get deskTabPainter => 'Painter';
14+
15+
@override
16+
String get deskTabKnowledge => 'Knowledge';
17+
18+
@override
19+
String get deskTabTools => 'Treasure';
20+
21+
@override
22+
String get deskTabMine => 'About';
23+
24+
@override
25+
String get mobileTabWidgets => 'Widgets';
26+
27+
@override
28+
String get mobileTabPainter => 'Painter';
29+
30+
@override
31+
String get mobileTabKnowledge => 'Knowledge';
32+
33+
@override
34+
String get mobileTabTools => 'Treasure';
35+
36+
@override
37+
String get mobileTabMine => 'Mine';
38+
}

lib/src/l10n/gen/app_l10n_zh.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import 'app_l10n.dart';
2+
3+
// ignore_for_file: type=lint
4+
5+
/// The translations for Chinese (`zh`).
6+
class AppL10nZh extends AppL10n {
7+
AppL10nZh([String locale = 'zh']) : super(locale);
8+
9+
@override
10+
String get deskTabWidgets => '组件集录';
11+
12+
@override
13+
String get deskTabPainter => '绘制集录';
14+
15+
@override
16+
String get deskTabKnowledge => '知识集锦';
17+
18+
@override
19+
String get deskTabTools => '工具宝箱';
20+
21+
@override
22+
String get deskTabMine => '应用信息';
23+
24+
@override
25+
String get mobileTabWidgets => '组件';
26+
27+
@override
28+
String get mobileTabPainter => '绘制';
29+
30+
@override
31+
String get mobileTabKnowledge => '知识';
32+
33+
@override
34+
String get mobileTabTools => '工具';
35+
36+
@override
37+
String get mobileTabMine => '我的';
38+
}

lib/src/navigation/model/app_tab.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import 'package:app/app.dart';
2+
import 'package:flutter/cupertino.dart';
3+
import 'package:flutter_unit/src/l10n/gen/app_l10n.dart';
4+
import 'package:tolyui/tolyui.dart';
5+
6+
enum AppTab {
7+
widgets('/widget', TolyIcon.icon_layout),
8+
painter('/painter', TolyIcon.dingzhi1),
9+
knowledge('/knowledge', TolyIcon.icon_artifact),
10+
tools('/tools', TolyIcon.icon_fast),
11+
mine('/account', TolyIcon.yonghu);
12+
13+
final IconData icon;
14+
final String path;
15+
16+
const AppTab(this.path, this.icon);
17+
18+
String label(AppL10n l10n) {
19+
if (kAppEnv.isDesktopUI) {
20+
return switch (this) {
21+
AppTab.widgets => l10n.deskTabWidgets,
22+
AppTab.painter => l10n.deskTabPainter,
23+
AppTab.knowledge => l10n.deskTabKnowledge,
24+
AppTab.tools => l10n.deskTabTools,
25+
AppTab.mine => l10n.deskTabMine,
26+
};
27+
}
28+
return switch (this) {
29+
AppTab.widgets => l10n.mobileTabWidgets,
30+
AppTab.painter => l10n.mobileTabPainter,
31+
AppTab.knowledge => l10n.mobileTabKnowledge,
32+
AppTab.tools => l10n.mobileTabTools,
33+
AppTab.mine => l10n.mobileTabMine,
34+
};
35+
}
36+
37+
MenuMeta menu(AppL10n l10n) => MenuMeta(
38+
label: label(l10n),
39+
icon: icon,
40+
router: path,
41+
);
42+
}

0 commit comments

Comments
 (0)