- make the refresh interval setting makes effect immediately.
- auto stop/restart status update when app goto background/resume
This commit is contained in:
Junyuan Feng
2022-01-02 19:06:26 +08:00
parent 7fb8c88ab8
commit e08f37fedc
6 changed files with 57 additions and 14 deletions

View File

@@ -31,16 +31,37 @@ class _MyHomePageState extends State<MyHomePage>
with
AutomaticKeepAliveClientMixin,
SingleTickerProviderStateMixin,
AfterLayoutMixin {
AfterLayoutMixin,
WidgetsBindingObserver {
final List<String> _tabs = ['Servers', 'En/Decode'];
late final TabController _tabController;
late final ServerProvider _serverProvider;
@override
void initState() {
super.initState();
_serverProvider = locator<ServerProvider>();
WidgetsBinding.instance?.addObserver(this);
_tabController = TabController(length: _tabs.length, vsync: this);
}
@override
void dispose() {
super.dispose();
WidgetsBinding.instance?.removeObserver(this);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
if (state == AppLifecycleState.paused) {
_serverProvider.stopAutoRefresh();
}
if (state == AppLifecycleState.resumed) {
_serverProvider.startAutoRefresh();
}
}
@override
Widget build(BuildContext context) {
setTransparentNavigationBar(context);

View File

@@ -210,8 +210,8 @@ class _ServerDetailPageState extends State<ServerDetailPage>
_buildMemExplain(convertMB(ss.memory.used), pColor),
_buildMemExplain(
convertMB(ss.memory.cache), pColor.withAlpha(77)),
_buildMemExplain(
convertMB(ss.memory.total - ss.memory.avail), progressColor.resolve(context))
_buildMemExplain(convertMB(ss.memory.total - ss.memory.used),
progressColor.resolve(context))
],
),
const SizedBox(
@@ -243,7 +243,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
));
}
Widget _buildMemExplain(String type, Color color) {
Widget _buildMemExplain(String value, Color color) {
return Row(
children: [
Container(
@@ -252,7 +252,12 @@ class _ServerDetailPageState extends State<ServerDetailPage>
width: 11,
),
const SizedBox(width: 4),
Text(type, style: style11, textScaleFactor: 1.0)
Text(
value,
style: style11,
textScaleFactor: 1.0,
textAlign: TextAlign.center,
)
],
);
}

View File

@@ -67,7 +67,7 @@ class _ServerPageState extends State<ServerPage>
child: AnimationLimiter(
child: Column(
children: AnimationConfiguration.toStaggeredList(
duration: const Duration(milliseconds: 777),
duration: const Duration(milliseconds: 477),
childAnimationBuilder: (widget) => SlideAnimation(
verticalOffset: 77.0,
child: FadeInAnimation(
@@ -155,7 +155,9 @@ class _ServerPageState extends State<ServerPage>
accelerationCurve: Curves.linear,
decelerationDuration: const Duration(seconds: 3),
decelerationCurve: Curves.linear,
text: topRightStr, textScaleFactor: 1.0, style: style),
text: topRightStr,
textScaleFactor: 1.0,
style: style),
)
: Text(topRightStr, style: style, textScaleFactor: 1.0),
],

View File

@@ -3,6 +3,7 @@ import 'package:flutter_material_color_picker/flutter_material_color_picker.dart
import 'package:provider/provider.dart';
import 'package:toolbox/core/update.dart';
import 'package:toolbox/data/provider/app.dart';
import 'package:toolbox/data/provider/server.dart';
import 'package:toolbox/data/res/build_data.dart';
import 'package:toolbox/data/res/color.dart';
import 'package:toolbox/data/store/setting.dart';
@@ -22,6 +23,7 @@ class _SettingPageState extends State<SettingPage> {
double _intervalValue = 0;
late Color priColor;
static const textStyle = TextStyle(fontSize: 14);
late final ServerProvider _serverProvider;
@override
void didChangeDependencies() {
@@ -32,6 +34,7 @@ class _SettingPageState extends State<SettingPage> {
@override
void initState() {
super.initState();
_serverProvider = locator<ServerProvider>();
_store = locator<SettingStore>();
_intervalValue = _store.serverStatusUpdateInterval.fetch()!.toDouble();
}
@@ -88,7 +91,7 @@ class _SettingPageState extends State<SettingPage> {
textAlign: TextAlign.start,
),
subtitle: const Text(
'Will take effect the next time app launches.',
'Will take effect immediately.',
style: TextStyle(color: Colors.grey),
),
trailing: Text('${_intervalValue.toInt()} s'),
@@ -104,8 +107,10 @@ class _SettingPageState extends State<SettingPage> {
_intervalValue = newValue;
});
},
onChangeEnd: (val) =>
_store.serverStatusUpdateInterval.put(val.toInt()),
onChangeEnd: (val) {
_store.serverStatusUpdateInterval.put(val.toInt());
_serverProvider.startAutoRefresh();
},
label: '${_intervalValue.toInt()} seconds',
divisions: 10,
),