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