Skip to content

Commit bc09c33

Browse files
committed
[camera_avfoundation] Refactor Radio widgets in example
Refactors the `camera_avfoundation` example to use a new `RadioGroup` widget. This removes deprecated `onChanged` logic from each `RadioListTile` and moves it to the parent `RadioGroup`.
1 parent 8109fb3 commit bc09c33

File tree

1 file changed

+14
-13
lines changed
  • packages/camera/camera_avfoundation/example/lib

1 file changed

+14
-13
lines changed

packages/camera/camera_avfoundation/example/lib/main.dart

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -579,14 +579,6 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
579579
Widget _cameraTogglesRowWidget() {
580580
final List<Widget> toggles = <Widget>[];
581581

582-
void onChanged(CameraDescription? description) {
583-
if (description == null) {
584-
return;
585-
}
586-
587-
onNewCameraSelected(description);
588-
}
589-
590582
if (_cameras.isEmpty) {
591583
SchedulerBinding.instance.addPostFrameCallback((_) async {
592584
showInSnackBar('No camera found.');
@@ -599,18 +591,27 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
599591
width: 90.0,
600592
child: RadioListTile<CameraDescription>(
601593
title: Icon(getCameraLensIcon(cameraDescription.lensDirection)),
602-
groupValue: controller?.description,
603594
value: cameraDescription,
604-
onChanged: (controller?.value.isRecordingVideo ?? false)
605-
? null
606-
: onChanged,
607595
),
608596
),
609597
);
610598
}
611599
}
612600

613-
return Row(children: toggles);
601+
final isRecording = controller?.value.isRecordingVideo ?? false;
602+
603+
return RadioGroup<CameraDescription>(
604+
groupValue: controller?.description,
605+
onChanged: (CameraDescription? description) {
606+
if (isRecording) {
607+
return;
608+
}
609+
if (description != null) {
610+
onNewCameraSelected(description);
611+
}
612+
},
613+
child: Row(children: toggles),
614+
);
614615
}
615616

616617
String timestamp() => DateTime.now().millisecondsSinceEpoch.toString();

0 commit comments

Comments
 (0)