Skip to content

Commit

Permalink
Fix switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Pante committed Jun 25, 2024
1 parent d3d8b0b commit 23417f0
Showing 1 changed file with 13 additions and 31 deletions.
44 changes: 13 additions & 31 deletions samples/lib/widgets/switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,18 @@ class SwitchPage extends SampleScaffold {
});

@override
Widget child(BuildContext context) => const Switch();
}

class Switch extends StatefulWidget {
const Switch({super.key});

@override
State<Switch> createState() => _SwitchState();
}

class _SwitchState extends State<Switch> {
late final ValueNotifier<bool> notifier;

@override
void initState() {
super.initState();
notifier = ValueNotifier(false);
}

@override
Widget build(BuildContext context) => Padding(
padding: const EdgeInsets.all(16),
child: ValueListenableBuilder(
valueListenable: notifier,
builder: (context, _, __) => FSwitch(
value: true,
autofocus: true,
onChanged: (value) {},
Widget child(BuildContext context) {
final notifier = ValueNotifier(false);
return Padding(
padding: const EdgeInsets.all(16),
child: ValueListenableBuilder(
valueListenable: notifier,
builder: (context, _, __) => FSwitch(
value: notifier.value,
autofocus: true,
onChanged: (value) => notifier.value = value,
),
),
),
);
);
}
}

0 comments on commit 23417f0

Please sign in to comment.