|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:share_plus/share_plus.dart'; |
| 3 | + |
| 4 | +class ExcludedCupertinoActivityTypePage extends StatefulWidget { |
| 5 | + final List<CupertinoActivityType>? excludedActivityType; |
| 6 | + |
| 7 | + const ExcludedCupertinoActivityTypePage({ |
| 8 | + super.key, |
| 9 | + this.excludedActivityType, |
| 10 | + }); |
| 11 | + |
| 12 | + @override |
| 13 | + State<StatefulWidget> createState() => _ExcludedActivityTypePageState(); |
| 14 | +} |
| 15 | + |
| 16 | +class _ExcludedActivityTypePageState |
| 17 | + extends State<ExcludedCupertinoActivityTypePage> { |
| 18 | + final List<String> options = []; |
| 19 | + final List<String> selected = []; |
| 20 | + |
| 21 | + @override |
| 22 | + void initState() { |
| 23 | + for (final type in CupertinoActivityType.values) { |
| 24 | + options.add(type.value); |
| 25 | + } |
| 26 | + if (widget.excludedActivityType != null && |
| 27 | + widget.excludedActivityType!.isNotEmpty) { |
| 28 | + for (final type in widget.excludedActivityType!) { |
| 29 | + selected.add(type.value); |
| 30 | + } |
| 31 | + } |
| 32 | + super.initState(); |
| 33 | + } |
| 34 | + |
| 35 | + @override |
| 36 | + Widget build(BuildContext context) { |
| 37 | + return Scaffold( |
| 38 | + appBar: AppBar( |
| 39 | + title: const Text('Excluded Activity Type'), |
| 40 | + actions: [ |
| 41 | + IconButton( |
| 42 | + icon: const Icon(Icons.check), |
| 43 | + onPressed: () { |
| 44 | + final List<CupertinoActivityType> tempSelected = []; |
| 45 | + for (final String type in selected) { |
| 46 | + tempSelected.add( |
| 47 | + CupertinoActivityType.values |
| 48 | + .firstWhere((e) => e.value == type), |
| 49 | + ); |
| 50 | + } |
| 51 | + Navigator.pop(context, tempSelected); |
| 52 | + }, |
| 53 | + ), |
| 54 | + ], |
| 55 | + ), |
| 56 | + body: ListView( |
| 57 | + children: options.map((option) { |
| 58 | + return CheckboxListTile( |
| 59 | + value: selected.contains(option), |
| 60 | + title: Text(option), |
| 61 | + controlAffinity: ListTileControlAffinity.leading, |
| 62 | + onChanged: (bool? checked) { |
| 63 | + setState(() { |
| 64 | + if (checked == true) { |
| 65 | + selected.add(option); |
| 66 | + } else { |
| 67 | + selected.remove(option); |
| 68 | + } |
| 69 | + }); |
| 70 | + }, |
| 71 | + ); |
| 72 | + }).toList(), |
| 73 | + ), |
| 74 | + ); |
| 75 | + } |
| 76 | +} |
0 commit comments