@@ -71,6 +71,7 @@ class _RelaySelectSheetState extends State<RelaySelectSheet> {
7171 final _searchController = TextEditingController ();
7272 late final DraggableScrollableController _sheetController;
7373 String _newValue = '' ;
74+ bool _isPoppingNavigation = false ;
7475
7576 Set <String > get checkedRelaysSet => Set .from (widget.controller.relays);
7677
@@ -102,7 +103,7 @@ class _RelaySelectSheetState extends State<RelaySelectSheet> {
102103 }
103104
104105 final normalizedSelectedRelays =
105- widget.controller.relays.map (removeProtocol);
106+ widget.controller.relays.map (removeProtocol);
106107
107108 if (normalizedSelectedRelays.contains (value)) {
108109 setState (() {
@@ -126,6 +127,21 @@ class _RelaySelectSheetState extends State<RelaySelectSheet> {
126127 });
127128
128129 _sheetController = DraggableScrollableController ();
130+ _sheetController.addListener (() {
131+ if (_sheetController.size <= 0.4 ) {
132+ _closeSheet ();
133+ }
134+ });
135+ }
136+
137+ _closeSheet () {
138+ if (_isPoppingNavigation) {
139+ return ;
140+ }
141+
142+ Navigator .pop (context);
143+
144+ _isPoppingNavigation = true ;
129145 }
130146
131147 @override
@@ -185,66 +201,70 @@ class _RelaySelectSheetState extends State<RelaySelectSheet> {
185201 itemBuilder: (context, rawIndex) {
186202 if (isValueNew && rawIndex == 0 ) {
187203 return PlatformWidget (
188- material: (context, _) => ListTile (
189- title: Text (
190- l10n.addNewValueLabel (_newValue),
191- ),
192- leading: const Icon (
193- Icons .add,
194- ),
195- onTap: () {
196- widget.controller.add (_searchController.value.text);
197- _searchController.clear ();
198- },
199- ),
200- cupertino: (context, _) => CupertinoButton (
201- child: Text (
202- l10n.addNewValueLabel (_newValue),
203- ),
204- onPressed: () {
205- widget.controller.add (_searchController.value.text);
206- _searchController.clear ();
207- },
208- ),
204+ material: (context, _) =>
205+ ListTile (
206+ title: Text (
207+ l10n.addNewValueLabel (_newValue),
208+ ),
209+ leading: const Icon (
210+ Icons .add,
211+ ),
212+ onTap: () {
213+ widget.controller.add (_searchController.value.text);
214+ _searchController.clear ();
215+ },
216+ ),
217+ cupertino: (context, _) =>
218+ CupertinoButton (
219+ child: Text (
220+ l10n.addNewValueLabel (_newValue),
221+ ),
222+ onPressed: () {
223+ widget.controller.add (_searchController.value.text);
224+ _searchController.clear ();
225+ },
226+ ),
209227 );
210228 }
211229
212230 final index = isValueNew ? rawIndex - 1 : rawIndex;
213231 final relay = allRelays[index];
214232
215233 return PlatformWidget (
216- material: (context, _) => CheckboxListTile (
217- title: Text (
218- relay.length >= 6 ? relay.substring (6 ) : relay,
219- ),
220- value: widget.controller.relays.contains (relay),
221- onChanged: (newValue) {
222- if (newValue == null ) {
223- return ;
224- }
225-
226- if (newValue) {
227- widget.controller.add (relay);
228- } else {
229- widget.controller.remove (relay);
230- }
231- },
232- ),
233- cupertino: (context, _) => CupertinoListTile (
234- title: Text (
235- relay.length >= 6 ? relay.substring (6 ) : relay,
236- ),
237- trailing: CupertinoSwitch (
238- value: widget.controller.relays.contains (relay),
239- onChanged: (newValue) {
240- if (newValue) {
241- widget.controller.add (relay);
242- } else {
243- widget.controller.remove (relay);
244- }
245- },
246- ),
247- ),
234+ material: (context, _) =>
235+ CheckboxListTile (
236+ title: Text (
237+ relay.length >= 6 ? relay.substring (6 ) : relay,
238+ ),
239+ value: widget.controller.relays.contains (relay),
240+ onChanged: (newValue) {
241+ if (newValue == null ) {
242+ return ;
243+ }
244+
245+ if (newValue) {
246+ widget.controller.add (relay);
247+ } else {
248+ widget.controller.remove (relay);
249+ }
250+ },
251+ ),
252+ cupertino: (context, _) =>
253+ CupertinoListTile (
254+ title: Text (
255+ relay.length >= 6 ? relay.substring (6 ) : relay,
256+ ),
257+ trailing: CupertinoSwitch (
258+ value: widget.controller.relays.contains (relay),
259+ onChanged: (newValue) {
260+ if (newValue) {
261+ widget.controller.add (relay);
262+ } else {
263+ widget.controller.remove (relay);
264+ }
265+ },
266+ ),
267+ ),
248268 );
249269 },
250270 );
@@ -259,58 +279,66 @@ class _RelaySelectSheetState extends State<RelaySelectSheet> {
259279 return DraggableScrollableSheet (
260280 expand: false ,
261281 controller: _sheetController,
262- builder: (context, controller) => ModalSheet (
263- child: Column (
264- children: < Widget > [
265- if (loadStatus == LoadStatus .loading)
266- Expanded (
267- child: Center (
268- child: PlatformCircularProgressIndicator (),
282+ builder: (context, controller) =>
283+ ModalSheet (
284+ child: Column (
285+ children: < Widget > [
286+ if (loadStatus == LoadStatus .loading)
287+ Expanded (
288+ child: Center (
289+ child: PlatformCircularProgressIndicator (),
290+ ),
291+ )
292+ else
293+ if (loadStatus == LoadStatus .error)
294+ Text (
295+ l10n.unknownError,
296+ style: TextStyle (
297+ color: getErrorColor (context),
298+ ),
299+ )
300+ else
301+ if (availableRelays.isNotEmpty)
302+ Expanded (
303+ child: buildRelaySelectSheet (controller),
304+ ),
305+ const SizedBox (height: MEDIUM_SPACE ),
306+ PlatformTextButton (
307+ material: (_, __) =>
308+ MaterialTextButtonData (
309+ icon: const Icon (Icons .shuffle),
310+ ),
311+ onPressed: loadStatus == LoadStatus .success
312+ ? () {
313+ final relays = availableRelays.toList ();
314+ relays.shuffle ();
315+
316+ widget.controller.clear ();
317+ widget.controller.addAll (relays.take (5 ).toList ());
318+ }
319+ : null ,
320+ child: Text (l10n.relaySelectSheet_selectRandomRelays (5 )),
269321 ),
270- )
271- else if (loadStatus == LoadStatus .error)
272- Text (
273- l10n.unknownError,
274- style: TextStyle (
275- color: getErrorColor (context),
322+ const SizedBox (height: SMALL_SPACE ),
323+ PlatformElevatedButton (
324+ onPressed: () {
325+ Navigator .of (context).pop ();
326+ },
327+ material: (_, __) =>
328+ MaterialElevatedButtonData (
329+ icon: const Icon (Icons .done),
330+ ),
331+ child: Text (l10n.closePositiveSheetAction),
276332 ),
277- )
278- else if (availableRelays.isNotEmpty)
279- Expanded (
280- child: buildRelaySelectSheet (controller),
281- ),
282- const SizedBox (height: MEDIUM_SPACE ),
283- PlatformTextButton (
284- material: (_, __) => MaterialTextButtonData (
285- icon: const Icon (Icons .shuffle),
286- ),
287- onPressed: loadStatus == LoadStatus .success
288- ? () {
289- final relays = availableRelays.toList ();
290- relays.shuffle ();
291-
292- widget.controller.clear ();
293- widget.controller.addAll (relays.take (5 ).toList ());
294- }
295- : null ,
296- child: Text (l10n.relaySelectSheet_selectRandomRelays (5 )),
297- ),
298- const SizedBox (height: SMALL_SPACE ),
299- PlatformElevatedButton (
300- onPressed: () {
301- Navigator .of (context).pop ();
302- },
303- material: (_, __) => MaterialElevatedButtonData (
304- icon: const Icon (Icons .done),
305- ),
306- child: Text (l10n.closePositiveSheetAction),
333+ SizedBox (
334+ height: MediaQuery
335+ .of (context)
336+ .viewInsets
337+ .bottom,
338+ )
339+ ],
307340 ),
308- SizedBox (
309- height: MediaQuery .of (context).viewInsets.bottom,
310- )
311- ],
312- ),
313- ),
341+ ),
314342 );
315343 }
316344}
0 commit comments