Skip to content

Commit 06070c2

Browse files
authored
fix(color-picking): Fix color picking failure and card overflow (#998)
1 parent bb0ada1 commit 06070c2

File tree

4 files changed

+56
-12
lines changed

4 files changed

+56
-12
lines changed

lib/app.dart

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class _MyAppState extends State<MyApp> {
2525
@override
2626
Widget build(BuildContext context) {
2727
_setup(context);
28+
2829
return ListenableBuilder(
2930
listenable: RNodes.app,
3031
builder: (context, _) {
@@ -39,6 +40,7 @@ class _MyAppState extends State<MyApp> {
3940

4041
Widget _build(BuildContext context) {
4142
final colorSeed = Color(Stores.setting.colorSeed.fetch());
43+
4244
UIs.colorSeed = colorSeed;
4345
UIs.primaryColor = colorSeed;
4446

@@ -61,14 +63,31 @@ class _MyAppState extends State<MyApp> {
6163
Widget _buildDynamicColor(BuildContext context) {
6264
return DynamicColorBuilder(
6365
builder: (light, dark) {
64-
final lightTheme = ThemeData(useMaterial3: true, colorScheme: light);
65-
final darkTheme = ThemeData(useMaterial3: true, brightness: Brightness.dark, colorScheme: dark);
66+
final lightSeed = light?.primary;
67+
final darkSeed = dark?.primary;
68+
69+
final lightTheme = ThemeData(
70+
useMaterial3: true,
71+
colorSchemeSeed: lightSeed,
72+
appBarTheme: AppBarTheme(scrolledUnderElevation: 0.0),
73+
);
74+
final darkTheme = ThemeData(
75+
useMaterial3: true,
76+
brightness: Brightness.dark,
77+
colorSchemeSeed: darkSeed,
78+
appBarTheme: AppBarTheme(scrolledUnderElevation: 0.0),
79+
);
80+
6681
if (context.isDark && dark != null) {
6782
UIs.primaryColor = dark.primary;
6883
UIs.colorSeed = dark.primary;
6984
} else if (!context.isDark && light != null) {
7085
UIs.primaryColor = light.primary;
7186
UIs.colorSeed = light.primary;
87+
} else {
88+
final fallbackColor = Color(Stores.setting.colorSeed.fetch());
89+
UIs.primaryColor = fallbackColor;
90+
UIs.colorSeed = fallbackColor;
7291
}
7392

7493
return _buildApp(context, light: lightTheme, dark: darkTheme);

lib/view/page/server/tab/tab.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,6 @@ class _ServerPageState extends ConsumerState<ServerPage>
346346

347347
static const _kCardHeightMin = 23.0;
348348
static const _kCardHeightFlip = 99.0;
349-
static const _kCardHeightNormal = 108.0;
349+
static const _kCardHeightNormal = 110.0;
350350
static const _kCardHeightMoveOutFuncs = 135.0;
351351
}

lib/view/page/setting/entries/app.dart

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,33 @@ extension _App on _AppSettingsPageState {
9494
}),
9595
onTap: () {
9696
withTextFieldController((ctrl) async {
97+
ctrl.text = Color(_setting.colorSeed.fetch()).toHex;
9798
await context.showRoundDialog(
9899
title: libL10n.primaryColorSeed,
99100
child: StatefulBuilder(
100101
builder: (context, setState) {
101102
final children = <Widget>[
102-
/// Plugin [dynamic_color] is not supported on iOS
103103
if (!isIOS)
104-
ListTile(
105-
title: Text(l10n.followSystem),
106-
trailing: StoreSwitch(
107-
prop: _setting.useSystemPrimaryColor,
108-
callback: (_) => setState(() {}),
109-
),
104+
DynamicColorBuilder(
105+
builder: (light, dark) {
106+
final supported = light != null || dark != null;
107+
if (!supported) {
108+
if (!_setting.useSystemPrimaryColor.fetch()) {
109+
_setting.useSystemPrimaryColor.put(false);
110+
WidgetsBinding.instance.addPostFrameCallback((_) {
111+
setState(() {});
112+
});
113+
}
114+
return const SizedBox.shrink();
115+
}
116+
return ListTile(
117+
title: Text(l10n.followSystem),
118+
trailing: StoreSwitch(
119+
prop: _setting.useSystemPrimaryColor,
120+
callback: (_) => setState(() {}),
121+
),
122+
);
123+
},
110124
),
111125
];
112126
if (!_setting.useSystemPrimaryColor.fetch()) {
@@ -129,12 +143,22 @@ extension _App on _AppSettingsPageState {
129143

130144
void _onSaveColor(String s) {
131145
final color = s.fromColorHex;
146+
132147
if (color == null) {
133148
context.showSnackBar(libL10n.fail);
134149
return;
135150
}
136-
UIs.colorSeed = color;
151+
152+
// Save the color seed to settings
137153
_setting.colorSeed.put(color.value255);
154+
155+
// Only update UIs colors if we're not in system mode
156+
if (!_setting.useSystemPrimaryColor.fetch()) {
157+
UIs.primaryColor = color;
158+
UIs.colorSeed = color;
159+
}
160+
161+
RNodes.app.notify();
138162
context.pop();
139163
}
140164

lib/view/page/setting/entry.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:convert';
22
import 'dart:io';
33

4+
import 'package:dynamic_color/dynamic_color.dart';
45
import 'package:fl_lib/fl_lib.dart';
56
import 'package:flutter/material.dart';
67
import 'package:flutter_highlight/theme_map.dart';
@@ -28,14 +29,14 @@ import 'package:server_box/view/page/setting/seq/srv_seq.dart';
2829
import 'package:server_box/view/page/setting/seq/virt_key.dart';
2930

3031
part 'about.dart';
32+
part 'entries/ai.dart';
3133
part 'entries/app.dart';
3234
part 'entries/container.dart';
3335
part 'entries/editor.dart';
3436
part 'entries/full_screen.dart';
3537
part 'entries/server.dart';
3638
part 'entries/sftp.dart';
3739
part 'entries/ssh.dart';
38-
part 'entries/ai.dart';
3940

4041
const _kIconSize = 23.0;
4142

0 commit comments

Comments
 (0)