Skip to content

Commit 2c1bcb1

Browse files
committed
Fix localization and text color for light and dark theme
1 parent b29f08a commit 2c1bcb1

15 files changed

Lines changed: 416 additions & 329 deletions

File tree

.github/workflows/flutter_ci_cd.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
with:
3333
flutter-version: ${{ env.FLUTTER_VERSION }}
3434
channel: master
35+
cache: true
3536

3637
- name: Install dependencies
3738
run: flutter pub get
@@ -75,7 +76,7 @@ jobs:
7576
uses: subosito/flutter-action@v2
7677
with:
7778
flutter-version: ${{ env.FLUTTER_VERSION }}
78-
channel: stable
79+
channel: master
7980
cache: true
8081

8182
- name: Install dependencies

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"python.terminal.activateEnvironment": true,
33
"python.terminal.activateEnvInCurrentTerminal": true,
4-
"python.defaultInterpreterPath": "${workspaceFolder}/venv/bin/python3"
4+
"python.defaultInterpreterPath": "${workspaceFolder}/venv/bin/python3",
5+
"cmake.ignoreCMakeListsMissing": true
56
}

assets/autogen_meta/data_content.json

Lines changed: 215 additions & 215 deletions
Large diffs are not rendered by default.

assets/content_icons/flutter.svg

Lines changed: 43 additions & 1 deletion
Loading

lib/components/appbar/appbar_view.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ class _AppBarViewState extends State<AppBarView> {
8080
child: AssetIcons.logo.image,
8181
),
8282
const SizedBox(width: 20),
83-
Text(appTitle, style: MaterialTheme.textTheme().titleMedium),
83+
Text(
84+
appTitle,
85+
style: MaterialTheme.textTheme().titleMedium!.copyWith(
86+
color: MaterialTheme.colorScheme(context).onBackground,
87+
),
88+
),
8489
],
8590
),
8691
bottom: TabBar(
@@ -93,9 +98,9 @@ class _AppBarViewState extends State<AppBarView> {
9398
indicatorSize: TabBarIndicatorSize.tab,
9499
dividerColor: Colors.transparent,
95100
tabs: [
96-
Tab(text: appLocalization.article.toUpperCase()),
97-
Tab(text: appLocalization.tool.toUpperCase()),
98-
Tab(text: appLocalization.project.toUpperCase()),
101+
Tab(text: appLocalization.article),
102+
Tab(text: appLocalization.tool),
103+
Tab(text: appLocalization.project),
99104
],
100105
),
101106
);

lib/components/category_item_icon.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ class CategoryItemIcon extends StatelessWidget {
99

1010
@override
1111
Widget build(BuildContext context) {
12+
var colorScheme = MaterialTheme.colorScheme(context);
1213
return Column(
1314
mainAxisSize: MainAxisSize.min,
1415
children: [
1516
Container(
1617
width: 64,
1718
decoration: BoxDecoration(
18-
color: MaterialTheme.colorScheme(context).surfaceContainer,
19+
color: MaterialTheme.colorScheme(context).background,
1920
border: Border.all(
2021
color: MaterialTheme.colorScheme(context).outline,
2122
width: 0.5,
@@ -37,6 +38,7 @@ class CategoryItemIcon extends StatelessWidget {
3738
title,
3839
textAlign: TextAlign.center,
3940
style: MaterialTheme.textTheme().labelSmall!.copyWith(
41+
color: colorScheme.primary,
4042
fontSize: 12,
4143
),
4244
),

lib/components/drawer/drawer_view.dart

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,47 +24,56 @@ class _DrawerViewState extends State<DrawerView> {
2424
DropdownMenuEntry<Locale>(value: Locale('zh', 'CN'), label: '中文'),
2525
];
2626

27-
Locale get locale => appSettings?.locale ?? Locale('en', 'US');
28-
2927
@override
3028
Widget build(BuildContext context) {
3129
var appLocalization = AppLocalizations.of(context)!;
32-
return Drawer(
33-
child: Column(
34-
mainAxisSize: MainAxisSize.min,
35-
children: [
36-
SizedBox(
37-
height: 80,
38-
child: DrawerHeader(
39-
child: Text(
40-
appLocalization.settings,
41-
style: MaterialTheme.textTheme().titleMedium!.copyWith(
42-
fontWeight: FontWeight.bold,
30+
var colorScheme = MaterialTheme.colorScheme(context);
31+
return ValueListenableBuilder(
32+
valueListenable:
33+
appSettings?.currentLocale ?? ValueNotifier(const Locale('en', 'US')),
34+
builder: (context, locale, child) => Drawer(
35+
child: SafeArea(
36+
child: Column(
37+
mainAxisSize: MainAxisSize.min,
38+
children: [
39+
SizedBox(
40+
height: 80,
41+
child: DrawerHeader(
42+
child: Text(
43+
appLocalization.settings,
44+
style: MaterialTheme.textTheme().titleMedium!.copyWith(
45+
fontWeight: FontWeight.bold,
46+
color: colorScheme.primary,
47+
),
48+
),
4349
),
4450
),
45-
),
46-
),
47-
Padding(
48-
padding: const EdgeInsets.all(8.0),
49-
child: DropdownMenu(
50-
dropdownMenuEntries: menuEntries,
51-
initialSelection: locale,
52-
onSelected: (value) => setState(() {
53-
appSettings?.locale = value;
54-
AppData().saveAppSettings();
55-
}),
56-
),
57-
),
58-
Padding(
59-
padding: const EdgeInsets.all(8.0),
60-
child: IconButton.outlined(
61-
onPressed: () {
62-
AppData().appSettings?.delete();
63-
},
64-
icon: Text("Clear Cache"),
65-
),
51+
Padding(
52+
padding: const EdgeInsets.all(8.0),
53+
child: DropdownMenu(
54+
dropdownMenuEntries: menuEntries,
55+
textStyle: MaterialTheme.textTheme().labelSmall?.copyWith(
56+
color: colorScheme.onSurface,
57+
),
58+
initialSelection: locale,
59+
onSelected: (value) => setState(() {
60+
appSettings?.locale = value;
61+
AppData().saveAppSettings();
62+
}),
63+
),
64+
),
65+
Padding(
66+
padding: const EdgeInsets.all(8.0),
67+
child: IconButton(
68+
onPressed: () {
69+
AppData().appSettings?.delete();
70+
},
71+
icon: Text("Clear Cache"),
72+
),
73+
),
74+
],
6675
),
67-
],
76+
),
6877
),
6978
);
7079
}

lib/components/main_view.dart

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ class _StateMainView extends State<MainView> {
2828

2929
bool isFullScreenModel = false;
3030

31-
Locale get locale => appSettings?.locale ?? Locale('en', 'US');
32-
3331
bool isLoading = false;
3432

3533
void onLoading() {
@@ -59,55 +57,61 @@ class _StateMainView extends State<MainView> {
5957
@override
6058
Widget build(BuildContext context) {
6159
MaterialTheme theme = MaterialTheme();
62-
return MaterialApp(
63-
debugShowCheckedModeBanner: false,
64-
locale: locale,
65-
builder: DevicePreview.appBuilder,
66-
localizationsDelegates: const [
67-
FlutterQuillLocalizations.delegate,
68-
...AppLocalizations.localizationsDelegates,
69-
GlobalMaterialLocalizations.delegate,
70-
GlobalWidgetsLocalizations.delegate,
71-
GlobalCupertinoLocalizations.delegate,
72-
],
73-
supportedLocales: AppLocalizations.supportedLocales,
74-
theme: theme.light(),
75-
darkTheme: theme.dark(),
76-
highContrastTheme: theme.lightMediumContrast(),
77-
highContrastDarkTheme: theme.darkMediumContrast(),
78-
scrollBehavior: const MaterialScrollBehavior().copyWith(
79-
scrollbars: false,
80-
),
81-
navigatorKey: Navigation().navigatorKey,
82-
home: Builder(
83-
builder: (context) {
84-
return Stack(
85-
children: [
86-
AppLayout(
87-
defaultWidget: DefaultTabController(
88-
animationDuration: Duration.zero,
89-
initialIndex: 1,
90-
length: 3,
91-
child: Scaffold(
92-
drawer: DrawerView(),
93-
appBar: isFullScreenModel ? null : AppBarView(),
94-
body: SafeArea(
95-
child: ContentView(isFullScreenModel: isFullScreenModel),
96-
),
97-
floatingActionButton: ToggleFullscreenView(
98-
onSreenStateChange: (bool isFullScreen) => setState(() {
99-
isFullScreenModel = isFullScreen;
100-
}),
60+
return ValueListenableBuilder<Locale>(
61+
valueListenable:
62+
appSettings?.currentLocale ?? ValueNotifier(const Locale('en', 'US')),
63+
builder: (context, locale, child) => MaterialApp(
64+
debugShowCheckedModeBanner: false,
65+
locale: locale,
66+
builder: DevicePreview.appBuilder,
67+
localizationsDelegates: const [
68+
FlutterQuillLocalizations.delegate,
69+
...AppLocalizations.localizationsDelegates,
70+
GlobalMaterialLocalizations.delegate,
71+
GlobalWidgetsLocalizations.delegate,
72+
GlobalCupertinoLocalizations.delegate,
73+
],
74+
supportedLocales: AppLocalizations.supportedLocales,
75+
theme: theme.light(),
76+
darkTheme: theme.dark(),
77+
highContrastTheme: theme.lightHighContrast(),
78+
highContrastDarkTheme: theme.dark(),
79+
scrollBehavior: const MaterialScrollBehavior().copyWith(
80+
scrollbars: false,
81+
),
82+
navigatorKey: Navigation().navigatorKey,
83+
home: Builder(
84+
builder: (context) {
85+
return Stack(
86+
children: [
87+
AppLayout(
88+
defaultWidget: DefaultTabController(
89+
animationDuration: Duration.zero,
90+
initialIndex: 1,
91+
length: 3,
92+
child: Scaffold(
93+
drawer: DrawerView(),
94+
appBar: isFullScreenModel ? null : AppBarView(),
95+
body: SafeArea(
96+
child: ContentView(
97+
isFullScreenModel: isFullScreenModel,
98+
),
99+
),
100+
floatingActionButton: ToggleFullscreenView(
101+
onSreenStateChange: (bool isFullScreen) => setState(() {
102+
isFullScreenModel = isFullScreen;
103+
}),
104+
),
101105
),
102106
),
107+
context: context,
103108
),
104-
context: context,
105-
),
106-
if (isLoading)
107-
const Positioned.fill(child: Center(child: LoadingScreen())),
108-
],
109-
);
110-
},
109+
if (isLoading)
110+
const Positioned.fill(child: Center(child: LoadingScreen())),
111+
],
112+
);
113+
},
114+
),
111115
),
112116
);
113117
}

lib/components/tab_bar_layout_navigation_view.dart

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ class TabBarLayoutNavigationView extends StatefulWidget {
2020
}
2121

2222
class _TabBarLayoutNavigtionState extends State<TabBarLayoutNavigationView> {
23-
24-
var titleStyle = MaterialTheme.textTheme().titleMedium;
23+
var titleStyle = MaterialTheme.textTheme().titleSmall;
2524

26-
List<TextSpan>? getNavItemWidget() {
25+
List<TextSpan>? getNavItemWidget(MaterialScheme colorScheme) {
2726
var items = widget.navigationTitleItems;
2827
if (items == null) {
2928
return null;
@@ -35,19 +34,26 @@ class _TabBarLayoutNavigtionState extends State<TabBarLayoutNavigationView> {
3534
for (final (index, item) in items.indexed) {
3635
if (index == lastIndex) {
3736
item.setTitleStyle(
38-
titleStyle!.copyWith(color: Colors.blue),
37+
titleStyle!.copyWith(
38+
color: colorScheme.primary,
39+
fontWeight: FontWeight.w500,
40+
),
3941
);
4042
break;
4143
}
4244
item.setTitleStyle(
43-
titleStyle!.copyWith(color: Colors.grey),
45+
titleStyle!.copyWith(
46+
color: colorScheme.primary,
47+
fontWeight: FontWeight.w500,
48+
),
4449
);
4550
}
4651
return items.map((e) => e.titleWidget).toList();
4752
}
4853

4954
@override
5055
Widget build(BuildContext context) {
56+
var colorScheme = MaterialTheme.colorScheme(context);
5157
return Padding(
5258
padding: const EdgeInsets.all(8.0),
5359
child: Row(
@@ -58,13 +64,17 @@ class _TabBarLayoutNavigtionState extends State<TabBarLayoutNavigationView> {
5864
maxLines: 1,
5965
overflow: TextOverflow.ellipsis,
6066
text: TextSpan(
61-
text: widget.defaultText,
62-
style: titleStyle!.copyWith(color: Colors.grey),
63-
recognizer: widget.defaultTextClick != null
64-
? (TapGestureRecognizer()
67+
text: widget.defaultText,
68+
style: titleStyle!.copyWith(
69+
color: colorScheme.primary,
70+
fontWeight: FontWeight.w600,
71+
),
72+
recognizer: widget.defaultTextClick != null
73+
? (TapGestureRecognizer()
6574
..onTap = () => widget.defaultTextClick!())
66-
: null,
67-
children: getNavItemWidget()),
75+
: null,
76+
children: getNavItemWidget(colorScheme),
77+
),
6878
),
6979
),
7080
],

0 commit comments

Comments
 (0)