Sync append enter setting on resume
This commit is contained in:
@@ -158,7 +158,7 @@ class InputSyncPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _InputSyncPageState extends State<InputSyncPage>
|
||||
with TickerProviderStateMixin {
|
||||
with TickerProviderStateMixin, WidgetsBindingObserver {
|
||||
static const _hostKey = 'server_host';
|
||||
static const _portKey = 'server_port';
|
||||
static const _historyKey = 'send_history';
|
||||
@@ -188,6 +188,7 @@ class _InputSyncPageState extends State<InputSyncPage>
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
statusPulseController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 1300),
|
||||
@@ -206,6 +207,7 @@ class _InputSyncPageState extends State<InputSyncPage>
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
stateSubscription?.cancel();
|
||||
statusPulseController.dispose();
|
||||
radarPulseController.dispose();
|
||||
@@ -216,8 +218,16 @@ class _InputSyncPageState extends State<InputSyncPage>
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
unawaited(_syncAppendEnterFromPrefs());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadSavedState() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.reload();
|
||||
final nativeState = await api.getState();
|
||||
if (!mounted) {
|
||||
return;
|
||||
@@ -449,6 +459,19 @@ class _InputSyncPageState extends State<InputSyncPage>
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _syncAppendEnterFromPrefs() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.reload();
|
||||
final nextAppendEnter = prefs.getBool(_appendEnterKey) ?? false;
|
||||
if (!mounted || nextAppendEnter == appendEnter) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
appendEnter = nextAppendEnter;
|
||||
});
|
||||
}
|
||||
|
||||
void _restoreHistory(String text) {
|
||||
inputController.text = text;
|
||||
inputController.selection = TextSelection.collapsed(offset: text.length);
|
||||
|
||||
Reference in New Issue
Block a user