-
Notifications
You must be signed in to change notification settings - Fork 28.6k
Application state is reset when connecting or disconnecting external peripherals #168100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Touched base with jmagman (no ping), since this was identified as specific to the embedder, applied |
Looks like this issue stems from configuration changes causing an application recreation. Did some digging and found out that we need to add If this is a P0 for you team, I would recommend adding |
Closing this issue as WAI thanks to @ash2moon's investigation. You can read more about the motivation to close this issue here. Feel free to reopen if further discussion is needed. Below is the original sample code updated with state restoration. Enabling state restoration in the original sample code involves:
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
),
home: const MyHomePage(),
debugShowCheckedModeBanner: false,
restorationScopeId: 'materialRoot',
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> with RestorationMixin {
final RestorableTextEditingController _textController =
RestorableTextEditingController();
final RestorableIntN _radioValue = RestorableIntN(1);
final RestorableBool _isChecked = RestorableBool(false);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(16.0),
child: ListView(
children: <Widget>[
const SizedBox(height: 8),
TextField(
controller: _textController.value,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Enter text',
hintText: 'Type something here',
prefixIcon: Icon(Icons.edit),
),
),
const SizedBox(height: 20),
Column(
children: <Widget>[
RadioListTile<int>(
title: const Text('Radio Option 1'),
value: 1,
groupValue: _radioValue.value,
onChanged: (int? value) {
setState(() {
_radioValue.value = value;
});
},
),
RadioListTile<int>(
title: const Text('Radio Option 2'),
value: 2,
groupValue: _radioValue.value,
onChanged: (int? value) {
setState(() {
_radioValue.value = value;
});
},
),
RadioListTile<int>(
title: const Text('Radio Option 3'),
value: 3,
groupValue: _radioValue.value,
onChanged: (int? value) {
setState(() {
_radioValue.value = value;
});
},
),
],
),
const SizedBox(height: 20),
CheckboxListTile(
title: const Text('Enable Checkbox'),
value: _isChecked.value,
onChanged: (bool? value) {
setState(() {
_isChecked.value = value ?? false;
});
},
),
const SizedBox(height: 20),
],
),
),
);
}
@override
void dispose() {
_textController.dispose();
super.dispose();
}
@override
String? get restorationId => 'myHomePage';
@override
void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
registerForRestoration(_textController, 'textController');
registerForRestoration(_radioValue, 'radioValue');
registerForRestoration(_isChecked, 'isChecked');
}
} |
Uh oh!
There was an error while loading. Please reload this page.
Steps to reproduce
Expected results
Applications state is not affected by connecting/disconnecting external peripherals.
Actual results
Applications state is reset when connecting/disconnecting external peripherals.
Code sample
Code sample
Screenshots or Video
Screenshots / Video demonstration
Screen_Recording_20250430_134352.mp4
Reproduced On
The text was updated successfully, but these errors were encountered: