From ae3e172033d71fe67ac39d9110ee7b78e45f249f Mon Sep 17 00:00:00 2001 From: Juan Gilsanz Polo Date: Tue, 30 Jan 2024 01:04:06 +0100 Subject: [PATCH] Changed response status bottom sheet --- .../logs/filters/filter_status_modal.dart | 244 ++++++++---------- .../logs/filters/logs_filters_modal.dart | 6 +- lib/widgets/list_bottom_sheet.dart | 14 +- 3 files changed, 122 insertions(+), 142 deletions(-) diff --git a/lib/screens/logs/filters/filter_status_modal.dart b/lib/screens/logs/filters/filter_status_modal.dart index c08d9a87..d4e41555 100644 --- a/lib/screens/logs/filters/filter_status_modal.dart +++ b/lib/screens/logs/filters/filter_status_modal.dart @@ -1,9 +1,11 @@ -import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:adguard_home_manager/widgets/list_bottom_sheet.dart'; + import 'package:adguard_home_manager/providers/logs_provider.dart'; class FilterStatusModal extends StatefulWidget { @@ -33,169 +35,141 @@ class _FilterStatusModalState extends State { Widget build(BuildContext context) { final logsProvider = Provider.of(context); - void apply() async { - logsProvider.setSelectedResultStatus(value: selectedResultStatus); - - Navigator.pop(context); - } - if (widget.dialog == true) { return Dialog( child: ConstrainedBox( constraints: const BoxConstraints( maxWidth: 400 ), - child: _Content( - onApply: apply, - updateSelectedResultStatus: (v) => setState(() => selectedResultStatus = v), - selectedResultStatus: selectedResultStatus, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Flexible( + child: SingleChildScrollView( + child: Wrap( + children: [ + Padding( + padding: const EdgeInsets.only(top: 16, left: 16), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + CloseButton( + onPressed: () => Navigator.pop(context), + ), + const SizedBox(width: 12), + Text( + AppLocalizations.of(context)!.responseStatus, + style: const TextStyle( + fontSize: 22 + ), + ) + ], + ), + ), + Container(height: 16), + _ItemsList( + selectedResultStatus: logsProvider.selectedResultStatus, + updateSelectedResultStatus: (v) => logsProvider.setSelectedResultStatus(value: v), + ), + Container(height: 16) + ], + ), + ), + ), + ], ) ), ); } else { - return Container( - decoration: BoxDecoration( - borderRadius: const BorderRadius.only( - topLeft: Radius.circular(28), - topRight: Radius.circular(28) - ), - color: Theme.of(context).dialogBackgroundColor + return SizedBox( + height: 700, + child: ListBottomSheet( + icon: Icons.shield_rounded, + title: AppLocalizations.of(context)!.responseStatus, + initialChildSize: 1, + minChildSize: 0.5, + children: [ + _ItemsList( + selectedResultStatus: logsProvider.selectedResultStatus, + updateSelectedResultStatus: (v) => logsProvider.setSelectedResultStatus(value: v), + ) + ] ), - child: SafeArea( - child: _Content( - onApply: apply, - updateSelectedResultStatus: (v) => setState(() => selectedResultStatus = v), - selectedResultStatus: selectedResultStatus, - ), - ) ); } } } -class _Content extends StatelessWidget { +class _ItemsList extends StatelessWidget { final String selectedResultStatus; final void Function(String) updateSelectedResultStatus; - final void Function() onApply; - const _Content({ + const _ItemsList({ required this.selectedResultStatus, - required this.updateSelectedResultStatus, - required this.onApply, + required this.updateSelectedResultStatus }); @override Widget build(BuildContext context) { return Column( - mainAxisSize: MainAxisSize.min, children: [ - Flexible( - child: SingleChildScrollView( - child: Wrap( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Column( - children: [ - Padding( - padding: const EdgeInsets.only( - top: 24, - bottom: 16, - ), - child: Icon( - Icons.shield_rounded, - size: 24, - color: Theme.of(context).listTileTheme.iconColor - ), - ), - Text( - AppLocalizations.of(context)!.responseStatus, - style: TextStyle( - fontSize: 24, - fontWeight: FontWeight.w400, - color: Theme.of(context).colorScheme.onSurface - ), - ), - ], - ) - ], - ), - Container(height: 16), - _Item( - selectedResultStatus: selectedResultStatus, - id: "all", - icon: Icons.shield_rounded, - label: AppLocalizations.of(context)!.all, - onChanged: updateSelectedResultStatus - ), - _Item( - selectedResultStatus: selectedResultStatus, - id: "filtered", - icon: Icons.shield_rounded, - label: AppLocalizations.of(context)!.filtered, - onChanged: updateSelectedResultStatus - ), - _Item( - selectedResultStatus: selectedResultStatus, - id: "processed", - icon: Icons.verified_user_rounded, - label: AppLocalizations.of(context)!.processedRow, - onChanged: updateSelectedResultStatus - ), - _Item( - selectedResultStatus: selectedResultStatus, - id: "whitelisted", - icon: Icons.verified_user_rounded, - label: AppLocalizations.of(context)!.processedWhitelistRow, - onChanged: updateSelectedResultStatus - ), - _Item( - selectedResultStatus: selectedResultStatus, - id: "blocked", - icon: Icons.gpp_bad_rounded, - label: AppLocalizations.of(context)!.blocked, - onChanged: updateSelectedResultStatus - ), - _Item( - selectedResultStatus: selectedResultStatus, - id: "blocked_safebrowsing", - icon: Icons.gpp_bad_rounded, - label: AppLocalizations.of(context)!.blockedSafeBrowsingRow, - onChanged: updateSelectedResultStatus - ), - _Item( - selectedResultStatus: selectedResultStatus, - id: "blocked_parental", - icon: Icons.gpp_bad_rounded, - label: AppLocalizations.of(context)!.blockedParentalRow, - onChanged: updateSelectedResultStatus - ), - _Item( - selectedResultStatus: selectedResultStatus, - id: "safe_search", - icon: Icons.gpp_bad_rounded, - label: AppLocalizations.of(context)!.blockedSafeSearchRow, - onChanged: updateSelectedResultStatus - ), - ], - ), - ), + _Item( + selectedResultStatus: selectedResultStatus, + id: "all", + icon: Icons.shield_rounded, + label: AppLocalizations.of(context)!.all, + onChanged: updateSelectedResultStatus ), - Padding( - padding: const EdgeInsets.all(24), - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - TextButton( - onPressed: onApply, - child: Text(AppLocalizations.of(context)!.apply) - ) - ], - ), + _Item( + selectedResultStatus: selectedResultStatus, + id: "filtered", + icon: Icons.shield_rounded, + label: AppLocalizations.of(context)!.filtered, + onChanged: updateSelectedResultStatus + ), + _Item( + selectedResultStatus: selectedResultStatus, + id: "processed", + icon: Icons.verified_user_rounded, + label: AppLocalizations.of(context)!.processedRow, + onChanged: updateSelectedResultStatus + ), + _Item( + selectedResultStatus: selectedResultStatus, + id: "whitelisted", + icon: Icons.verified_user_rounded, + label: AppLocalizations.of(context)!.processedWhitelistRow, + onChanged: updateSelectedResultStatus + ), + _Item( + selectedResultStatus: selectedResultStatus, + id: "blocked", + icon: Icons.gpp_bad_rounded, + label: AppLocalizations.of(context)!.blocked, + onChanged: updateSelectedResultStatus + ), + _Item( + selectedResultStatus: selectedResultStatus, + id: "blocked_safebrowsing", + icon: Icons.gpp_bad_rounded, + label: AppLocalizations.of(context)!.blockedSafeBrowsingRow, + onChanged: updateSelectedResultStatus + ), + _Item( + selectedResultStatus: selectedResultStatus, + id: "blocked_parental", + icon: Icons.gpp_bad_rounded, + label: AppLocalizations.of(context)!.blockedParentalRow, + onChanged: updateSelectedResultStatus + ), + _Item( + selectedResultStatus: selectedResultStatus, + id: "safe_search", + icon: Icons.gpp_bad_rounded, + label: AppLocalizations.of(context)!.blockedSafeSearchRow, + onChanged: updateSelectedResultStatus ), - if (Platform.isIOS) const SizedBox(height: 16) ], ); } diff --git a/lib/screens/logs/filters/logs_filters_modal.dart b/lib/screens/logs/filters/logs_filters_modal.dart index 9f776663..b02dbd2e 100644 --- a/lib/screens/logs/filters/logs_filters_modal.dart +++ b/lib/screens/logs/filters/logs_filters_modal.dart @@ -82,10 +82,9 @@ class _FiltersList extends StatelessWidget { final void Function() onClearSearch; const _FiltersList({ - Key? key, required this.searchController, required this.onClearSearch, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -125,7 +124,8 @@ class _FiltersList extends StatelessWidget { dialog: false, ), isScrollControlled: true, - backgroundColor: Colors.transparent + backgroundColor: Colors.transparent, + useSafeArea: true ); } } diff --git a/lib/widgets/list_bottom_sheet.dart b/lib/widgets/list_bottom_sheet.dart index 2f8bd03e..219df8ce 100644 --- a/lib/widgets/list_bottom_sheet.dart +++ b/lib/widgets/list_bottom_sheet.dart @@ -4,12 +4,18 @@ class ListBottomSheet extends StatelessWidget { final IconData icon; final String title; final List children; + final double? initialChildSize; + final double? minChildSize; + final double? maxChildSize; const ListBottomSheet({ super.key, required this.icon, required this.title, - required this.children + required this.children, + this.initialChildSize, + this.maxChildSize, + this.minChildSize, }); @override @@ -17,9 +23,9 @@ class ListBottomSheet extends StatelessWidget { return GestureDetector( onTap: () => Navigator.of(context).pop(), child: DraggableScrollableSheet( - initialChildSize: 0.6, - minChildSize: 0.3, - maxChildSize: 1, + initialChildSize: initialChildSize ?? 0.6, + minChildSize: minChildSize ?? 0.3, + maxChildSize: maxChildSize ?? 1, builder: (context, controller) { return Container( decoration: BoxDecoration(