Minimal reproduction:
import 'dart:async';
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(),
body: Center(child: TestSwitch()),
),
));
}
class TestSwitch extends StatefulWidget {
State<TestSwitch> createState() => _TestSwitchState();
}
class _TestSwitchState extends State<TestSwitch> {
static const kDisableSwitchOnChanged = true; // Change me!
bool value = true;
bool enabled = true;
Widget build(BuildContext context) {
return Switch(
value: value,
onChanged: enabled ? _onChanged : null,
);
}
void _onChanged(bool value) {
setState(() {
this.value = value;
if (kDisableSwitchOnChanged) {
enabled = false;
Timer(Duration(seconds: 1), () {
if (mounted) {
setState(() {
enabled = true;
});
}
});
}
});
}
}
If kDisableSwitchOnChanged is true, the switch toggle animation does not happen. It instead snaps to the end position.
For comparison, Android settings screen handles this correctly, and Cupertino switch handles it correctly.
cc @LongCatIsLooong
Minimal reproduction:
If kDisableSwitchOnChanged is true, the switch toggle animation does not happen. It instead snaps to the end position.
For comparison, Android settings screen handles this correctly, and Cupertino switch handles it correctly.
cc @LongCatIsLooong