fix: flutter remove setState in initState (#8807)

Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
dignow
2024-07-24 14:00:49 +08:00
committed by GitHub
parent 57d1b1ecc4
commit 79a1f888d6
12 changed files with 69 additions and 31 deletions

View File

@@ -129,7 +129,7 @@ class ConnectionManagerState extends State<ConnectionManager>
if (client != null) {
gFFI.chatModel.changeCurrentKey(MessageKey(client.peerId, client.id));
if (client.unreadChatMessageCount.value > 0) {
Future.delayed(Duration.zero, () {
WidgetsBinding.instance.addPostFrameCallback((_) {
client.unreadChatMessageCount.value = 0;
gFFI.chatModel.showChatPage(MessageKey(client.peerId, client.id));
});
@@ -399,7 +399,10 @@ class _CmHeaderState extends State<_CmHeader>
_time.value = _time.value + 1;
}
});
gFFI.serverModel.tabController.onSelected?.call(client.id.toString());
// Call onSelected in post frame callback, since we cannot guarantee that the callback will not call setState.
WidgetsBinding.instance.addPostFrameCallback((_) {
gFFI.serverModel.tabController.onSelected?.call(client.id.toString());
});
}
@override
@@ -732,7 +735,8 @@ class _CmControlPanel extends StatelessWidget {
child: buildButton(context,
color: MyTheme.accent,
onClick: null, onTapDown: (details) async {
final devicesInfo = await AudioInput.getDevicesInfo(true, true);
final devicesInfo =
await AudioInput.getDevicesInfo(true, true);
List<String> devices = devicesInfo['devices'] as List<String>;
if (devices.isEmpty) {
msgBox(
@@ -764,7 +768,8 @@ class _CmControlPanel extends StatelessWidget {
value: d,
groupValue: currentDevice,
onChanged: (v) {
if (v != null) AudioInput.setDevice(v, true, true);
if (v != null)
AudioInput.setDevice(v, true, true);
},
child: Container(
child: Text(