mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 15:24:35 +01:00
Optimized primary color fetching method
This commit is contained in:
@@ -49,7 +49,8 @@ class MyApp extends StatelessWidget {
|
|||||||
focusedBorder: UnderlineInputBorder(
|
focusedBorder: UnderlineInputBorder(
|
||||||
borderSide: BorderSide(color: primaryColor))),
|
borderSide: BorderSide(color: primaryColor))),
|
||||||
radioTheme: RadioThemeData(
|
radioTheme: RadioThemeData(
|
||||||
fillColor: getMaterialStateColor(primaryColor),),
|
fillColor: getMaterialStateColor(primaryColor),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
darkTheme: ThemeData.dark().copyWith(
|
darkTheme: ThemeData.dark().copyWith(
|
||||||
primaryColor: primaryColor,
|
primaryColor: primaryColor,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import 'package:toolbox/core/utils.dart';
|
|||||||
import 'package:toolbox/data/store/setting.dart';
|
import 'package:toolbox/data/store/setting.dart';
|
||||||
import 'package:toolbox/locator.dart';
|
import 'package:toolbox/locator.dart';
|
||||||
|
|
||||||
Color primaryColor = Color(locator<SettingStore>().primaryColor.fetch()!);
|
Color get primaryColor => Color(locator<SettingStore>().primaryColor.fetch()!);
|
||||||
|
|
||||||
class DynamicColor {
|
class DynamicColor {
|
||||||
/// 白天模式显示的颜色
|
/// 白天模式显示的颜色
|
||||||
|
|||||||
@@ -15,20 +15,20 @@ class SettingPage extends StatefulWidget {
|
|||||||
class _SettingPageState extends State<SettingPage> {
|
class _SettingPageState extends State<SettingPage> {
|
||||||
late SettingStore _store;
|
late SettingStore _store;
|
||||||
late int _selectedColorValue;
|
late int _selectedColorValue;
|
||||||
double _value = 0;
|
double _intervalValue = 0;
|
||||||
late Color _textColor;
|
late Color priColor;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
_textColor = Theme.of(context).textTheme.bodyText1!.color!;
|
priColor = primaryColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_store = locator<SettingStore>();
|
_store = locator<SettingStore>();
|
||||||
_value = _store.serverStatusUpdateInterval.fetch()!.toDouble();
|
_intervalValue = _store.serverStatusUpdateInterval.fetch()!.toDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -45,36 +45,43 @@ class _SettingPageState extends State<SettingPage> {
|
|||||||
ExpansionTile(
|
ExpansionTile(
|
||||||
tilePadding: EdgeInsets.zero,
|
tilePadding: EdgeInsets.zero,
|
||||||
childrenPadding: EdgeInsets.zero,
|
childrenPadding: EdgeInsets.zero,
|
||||||
title: Text(
|
textColor: priColor,
|
||||||
|
title: const Text(
|
||||||
'Server status update interval',
|
'Server status update interval',
|
||||||
style: TextStyle(fontSize: 14, color: _textColor),
|
style: TextStyle(fontSize: 14),
|
||||||
textAlign: TextAlign.start,
|
textAlign: TextAlign.start,
|
||||||
),
|
),
|
||||||
subtitle: const Text(
|
subtitle: const Text(
|
||||||
'Will take effect the next time app launches.',
|
'Will take effect the next time app launches.',
|
||||||
style: TextStyle(color: Colors.grey),
|
style: TextStyle(color: Colors.grey),
|
||||||
),
|
),
|
||||||
trailing: Text('${_value.toInt()} s'),
|
trailing: Text('${_intervalValue.toInt()} s'),
|
||||||
children: [
|
children: [
|
||||||
Slider(
|
Slider(
|
||||||
thumbColor: primaryColor,
|
thumbColor: priColor,
|
||||||
activeColor: primaryColor.withOpacity(0.7),
|
activeColor: priColor.withOpacity(0.7),
|
||||||
min: 0,
|
min: 0,
|
||||||
max: 10,
|
max: 10,
|
||||||
value: _value,
|
value: _intervalValue,
|
||||||
onChanged: (newValue) {
|
onChanged: (newValue) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_value = newValue;
|
_intervalValue = newValue;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onChangeEnd: (val) =>
|
onChangeEnd: (val) =>
|
||||||
_store.serverStatusUpdateInterval.put(val.toInt()),
|
_store.serverStatusUpdateInterval.put(val.toInt()),
|
||||||
label: '${_value.toInt()} seconds',
|
label: '${_intervalValue.toInt()} seconds',
|
||||||
divisions: 10,
|
divisions: 10,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 3,),
|
const SizedBox(
|
||||||
_value == 0.0 ? const Text('You set to 0, will not update automatically.') : const SizedBox(),
|
height: 3,
|
||||||
const SizedBox(height: 13,)
|
),
|
||||||
|
_intervalValue == 0.0
|
||||||
|
? const Text('You set to 0, will not update automatically.')
|
||||||
|
: const SizedBox(),
|
||||||
|
const SizedBox(
|
||||||
|
height: 13,
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -84,24 +91,24 @@ class _SettingPageState extends State<SettingPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildAppColorPreview() {
|
Widget _buildAppColorPreview() {
|
||||||
final nowAppColor = _store.primaryColor.fetch()!;
|
|
||||||
return ExpansionTile(
|
return ExpansionTile(
|
||||||
|
textColor: priColor,
|
||||||
tilePadding: EdgeInsets.zero,
|
tilePadding: EdgeInsets.zero,
|
||||||
childrenPadding: EdgeInsets.zero,
|
childrenPadding: EdgeInsets.zero,
|
||||||
children: [
|
children: [
|
||||||
_buildAppColorPicker(Color(nowAppColor)),
|
_buildAppColorPicker(priColor),
|
||||||
_buildColorPickerConfirmBtn()
|
_buildColorPickerConfirmBtn()
|
||||||
],
|
],
|
||||||
trailing: ClipOval(
|
trailing: ClipOval(
|
||||||
child: Container(
|
child: Container(
|
||||||
color: Color(nowAppColor),
|
color: priColor,
|
||||||
height: 27,
|
height: 27,
|
||||||
width: 27,
|
width: 27,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
title: Text(
|
title: const Text(
|
||||||
'App primary color',
|
'App primary color',
|
||||||
style: TextStyle(fontSize: 14, color: _textColor),
|
style: TextStyle(fontSize: 14),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user