part of '../neon_spreed.dart'; class SpreedSelectScreenDialog extends StatefulWidget { const SpreedSelectScreenDialog({ super.key, }); @override State createState() => _SpreedSelectScreenDialogState(); } class _SpreedSelectScreenDialogState extends State { List? sources; DesktopCapturerSource? selectedSource; late Timer timer; @override void initState() { super.initState(); unawaited( desktopCapturer.getSources(types: SourceType.values).then((final sources) { setState(() { this.sources = sources; }); }), ); timer = Timer.periodic(const Duration(seconds: 1), (final _) async { await desktopCapturer.updateSources(types: SourceType.values); }); } @override void dispose() { timer.cancel(); super.dispose(); } @override Widget build(final BuildContext context) => NeonDialog( title: Text(SpreedLocalizations.of(context).screenSharingSelectScreen), children: [ if (sources != null) ...[ for (final sourceType in SourceType.values.reversed) ...[ Text( sourceType == SourceType.Screen ? SpreedLocalizations.of(context).screenSharingSelectScreenScreens : SpreedLocalizations.of(context).screenSharingSelectScreenWindows, ), Wrap( spacing: 10, runSpacing: 10, children: [ for (final source in sources!.where((final source) => source.type == sourceType)) ...[ InkWell( onTap: () { setState(() { selectedSource = source; }); }, child: Container( padding: const EdgeInsets.all(5), decoration: BoxDecoration( border: Border.all( // Transparent to prevent the image from jumping around when changing the selected source color: selectedSource == source ? Theme.of(context).colorScheme.primary : Colors.transparent, width: 2, ), ), width: max(MediaQuery.of(context).size.width, MediaQuery.of(context).size.height) / 5, child: SpreedScreenPreview( source: source, ), ), ), ], ], ), const Divider(), ], ], const SizedBox( height: 10, ), ElevatedButton( onPressed: selectedSource == null ? null : () { Navigator.of(context).pop(selectedSource); }, child: Text(SpreedLocalizations.of(context).screenSharingSelectScreen), ), ], ); }