mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-05-25 11:22:23 +00:00
Refactor blocked services modal
This commit is contained in:
parent
9d1ae22bdd
commit
7690d5f1bc
2 changed files with 70 additions and 53 deletions
|
@ -1,5 +1,7 @@
|
||||||
// ignore_for_file: use_build_context_synchronously
|
// ignore_for_file: use_build_context_synchronously
|
||||||
|
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
@ -12,11 +14,11 @@ import 'package:adguard_home_manager/providers/filtering_provider.dart';
|
||||||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||||
|
|
||||||
class BlockedServicesScreen extends StatefulWidget {
|
class BlockedServicesScreen extends StatefulWidget {
|
||||||
final bool dialog;
|
final bool fullScreen;
|
||||||
|
|
||||||
const BlockedServicesScreen({
|
const BlockedServicesScreen({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.dialog
|
required this.fullScreen
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -180,7 +182,40 @@ class _BlockedServicesScreenStateWidget extends State<BlockedServicesScreen> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.dialog == true) {
|
if (widget.fullScreen == true) {
|
||||||
|
return Dialog.fullscreen(
|
||||||
|
child: Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
leading: CloseButton(onPressed: () => Navigator.pop(context)),
|
||||||
|
title: Text(AppLocalizations.of(context)!.blockedServices),
|
||||||
|
actions: [
|
||||||
|
IconButton(
|
||||||
|
onPressed: updateBlockedServices,
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.save_rounded
|
||||||
|
),
|
||||||
|
tooltip: AppLocalizations.of(context)!.save,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 10)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: RefreshIndicator(
|
||||||
|
onRefresh: () async {
|
||||||
|
final result = await filteringProvider.loadBlockedServices();
|
||||||
|
if (result == false) {
|
||||||
|
showSnacbkar(
|
||||||
|
appConfigProvider: appConfigProvider,
|
||||||
|
label: AppLocalizations.of(context)!.blockedServicesListNotLoaded,
|
||||||
|
color: Colors.red
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: body()
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
return Dialog(
|
return Dialog(
|
||||||
child: ConstrainedBox(
|
child: ConstrainedBox(
|
||||||
constraints: const BoxConstraints(
|
constraints: const BoxConstraints(
|
||||||
|
@ -228,35 +263,34 @@ class _BlockedServicesScreenStateWidget extends State<BlockedServicesScreen> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text(AppLocalizations.of(context)!.blockedServices),
|
|
||||||
actions: [
|
|
||||||
IconButton(
|
|
||||||
onPressed: updateBlockedServices,
|
|
||||||
icon: const Icon(
|
|
||||||
Icons.save_rounded
|
|
||||||
),
|
|
||||||
tooltip: AppLocalizations.of(context)!.save,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 10)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
body: RefreshIndicator(
|
|
||||||
onRefresh: () async {
|
|
||||||
final result = await filteringProvider.loadBlockedServices();
|
|
||||||
if (result == false) {
|
|
||||||
showSnacbkar(
|
|
||||||
appConfigProvider: appConfigProvider,
|
|
||||||
label: AppLocalizations.of(context)!.blockedServicesListNotLoaded,
|
|
||||||
color: Colors.red
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: body()
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void openBlockedServicesModal({
|
||||||
|
required BuildContext context,
|
||||||
|
required double width,
|
||||||
|
}) {
|
||||||
|
showGeneralDialog(
|
||||||
|
context: context,
|
||||||
|
barrierColor: !(width > 700 || !(Platform.isAndroid || Platform.isIOS))
|
||||||
|
?Colors.transparent
|
||||||
|
: Colors.black54,
|
||||||
|
transitionBuilder: (context, anim1, anim2, child) {
|
||||||
|
return SlideTransition(
|
||||||
|
position: Tween(
|
||||||
|
begin: const Offset(0, 1),
|
||||||
|
end: const Offset(0, 0)
|
||||||
|
).animate(
|
||||||
|
CurvedAnimation(
|
||||||
|
parent: anim1,
|
||||||
|
curve: Curves.easeInOutCubicEmphasized
|
||||||
|
)
|
||||||
|
),
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
pageBuilder: (context, animation, secondaryAnimation) => BlockedServicesScreen(
|
||||||
|
fullScreen: !(width > 700 || !(Platform.isAndroid || Platform.isIOS)),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
|
@ -149,26 +149,9 @@ class _FiltersState extends State<Filters> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void openBlockedServicesModal() {
|
void openBlockedServices() {
|
||||||
Future.delayed(const Duration(seconds: 0), () {
|
Future.delayed(const Duration(seconds: 0), () {
|
||||||
if (width > 700 || !(Platform.isAndroid || Platform.isIOS)) {
|
openBlockedServicesModal(context: context, width: width);
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) => const BlockedServicesScreen(
|
|
||||||
dialog: true,
|
|
||||||
),
|
|
||||||
barrierDismissible: false
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Navigator.of(context).push(
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => const BlockedServicesScreen(
|
|
||||||
dialog: false,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,7 +295,7 @@ class _FiltersState extends State<Filters> {
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
onTap: openBlockedServicesModal,
|
onTap: openBlockedServices,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.block),
|
const Icon(Icons.block),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue