mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-05-14 05:52:51 +00:00
Fab improvements and changed screens scaffolds
This commit is contained in:
parent
4ff8c7e123
commit
7219150e6c
16 changed files with 232 additions and 127 deletions
|
@ -1,11 +1,12 @@
|
|||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'package:adguard_home_manager/screens/clients/remove_domain_modal.dart';
|
||||
import 'package:animations/animations.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:adguard_home_manager/screens/clients/remove_domain_modal.dart';
|
||||
import 'package:adguard_home_manager/screens/clients/fab.dart';
|
||||
import 'package:adguard_home_manager/screens/clients/options_modal.dart';
|
||||
import 'package:adguard_home_manager/screens/clients/client_modal.dart';
|
||||
|
@ -16,18 +17,48 @@ import 'package:adguard_home_manager/models/clients.dart';
|
|||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
||||
|
||||
class AddedList extends StatelessWidget {
|
||||
class AddedList extends StatefulWidget {
|
||||
final ScrollController scrollController;
|
||||
final int loadStatus;
|
||||
final List<Client> data;
|
||||
final Future Function() fetchClients;
|
||||
|
||||
const AddedList({
|
||||
Key? key,
|
||||
required this.scrollController,
|
||||
required this.loadStatus,
|
||||
required this.data,
|
||||
required this.fetchClients
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<AddedList> createState() => _AddedListState();
|
||||
}
|
||||
|
||||
class _AddedListState extends State<AddedList> {
|
||||
late bool isVisible;
|
||||
|
||||
@override
|
||||
initState(){
|
||||
super.initState();
|
||||
|
||||
isVisible = true;
|
||||
widget.scrollController.addListener(() {
|
||||
if (widget.scrollController.position.userScrollDirection == ScrollDirection.reverse) {
|
||||
if (mounted && isVisible == true) {
|
||||
setState(() => isVisible = false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (widget.scrollController.position.userScrollDirection == ScrollDirection.forward) {
|
||||
if (mounted && isVisible == false) {
|
||||
setState(() => isVisible = true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final serversProvider = Provider.of<ServersProvider>(context);
|
||||
|
@ -55,6 +86,7 @@ class AddedList extends StatelessWidget {
|
|||
}
|
||||
}).toList();
|
||||
serversProvider.setClientsData(clientsData);
|
||||
appConfigProvider.setShowingSnackbar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.clientUpdatedSuccessfully),
|
||||
|
@ -64,6 +96,7 @@ class AddedList extends StatelessWidget {
|
|||
}
|
||||
else {
|
||||
appConfigProvider.addLog(result['log']);
|
||||
appConfigProvider.setShowingSnackbar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.clientNotUpdated),
|
||||
|
@ -85,6 +118,7 @@ class AddedList extends StatelessWidget {
|
|||
ClientsData clientsData = serversProvider.clients.data!;
|
||||
clientsData.clients = clientsData.clients.where((c) => c.name != client.name).toList();
|
||||
serversProvider.setClientsData(clientsData);
|
||||
appConfigProvider.setShowingSnackbar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.clientDeletedSuccessfully),
|
||||
|
@ -94,6 +128,7 @@ class AddedList extends StatelessWidget {
|
|||
}
|
||||
else {
|
||||
appConfigProvider.addLog(result['log']);
|
||||
appConfigProvider.setShowingSnackbar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.clientNotDeleted),
|
||||
|
@ -135,7 +170,7 @@ class AddedList extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
|
||||
switch (loadStatus) {
|
||||
switch (widget.loadStatus) {
|
||||
case 0:
|
||||
return SizedBox(
|
||||
width: double.maxFinite,
|
||||
|
@ -160,28 +195,28 @@ class AddedList extends StatelessWidget {
|
|||
case 1:
|
||||
return Stack(
|
||||
children: [
|
||||
if (data.isNotEmpty) ListView.builder(
|
||||
if (widget.data.isNotEmpty) ListView.builder(
|
||||
padding: const EdgeInsets.only(top: 0),
|
||||
itemCount: data.length,
|
||||
itemCount: widget.data.length,
|
||||
itemBuilder: (context, index) => ListTile(
|
||||
isThreeLine: true,
|
||||
onLongPress: () => openOptionsModal(data[index]),
|
||||
onTap: () => openClientModal(data[index]),
|
||||
onLongPress: () => openOptionsModal(widget.data[index]),
|
||||
onTap: () => openClientModal(widget.data[index]),
|
||||
title: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 5),
|
||||
child: Text(data[index].name),
|
||||
child: Text(widget.data[index].name),
|
||||
),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(data[index].ids.toString().replaceAll(RegExp(r'^\[|\]$'), '')),
|
||||
Text(widget.data[index].ids.toString().replaceAll(RegExp(r'^\[|\]$'), '')),
|
||||
const SizedBox(height: 7),
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.filter_list_rounded,
|
||||
size: 19,
|
||||
color: data[index].filteringEnabled == true
|
||||
color: widget.data[index].filteringEnabled == true
|
||||
? Colors.green
|
||||
: Colors.red,
|
||||
),
|
||||
|
@ -189,7 +224,7 @@ class AddedList extends StatelessWidget {
|
|||
Icon(
|
||||
Icons.vpn_lock_rounded,
|
||||
size: 18,
|
||||
color: data[index].safebrowsingEnabled == true
|
||||
color: widget.data[index].safebrowsingEnabled == true
|
||||
? Colors.green
|
||||
: Colors.red,
|
||||
),
|
||||
|
@ -197,7 +232,7 @@ class AddedList extends StatelessWidget {
|
|||
Icon(
|
||||
Icons.block,
|
||||
size: 18,
|
||||
color: data[index].parentalEnabled == true
|
||||
color: widget.data[index].parentalEnabled == true
|
||||
? Colors.green
|
||||
: Colors.red,
|
||||
),
|
||||
|
@ -205,7 +240,7 @@ class AddedList extends StatelessWidget {
|
|||
Icon(
|
||||
Icons.search_rounded,
|
||||
size: 19,
|
||||
color: data[index].safesearchEnabled == true
|
||||
color: widget.data[index].safesearchEnabled == true
|
||||
? Colors.green
|
||||
: Colors.red,
|
||||
)
|
||||
|
@ -215,7 +250,7 @@ class AddedList extends StatelessWidget {
|
|||
),
|
||||
)
|
||||
),
|
||||
if (data.isEmpty) SizedBox(
|
||||
if (widget.data.isEmpty) SizedBox(
|
||||
width: double.maxFinite,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
|
@ -230,18 +265,23 @@ class AddedList extends StatelessWidget {
|
|||
),
|
||||
const SizedBox(height: 30),
|
||||
TextButton.icon(
|
||||
onPressed: fetchClients,
|
||||
onPressed: widget.fetchClients,
|
||||
icon: const Icon(Icons.refresh_rounded),
|
||||
label: Text(AppLocalizations.of(context)!.refresh),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
const Positioned(
|
||||
bottom: 20,
|
||||
AnimatedPositioned(
|
||||
duration: const Duration(milliseconds: 100),
|
||||
curve: Curves.easeInOut,
|
||||
bottom: isVisible ?
|
||||
appConfigProvider.showingSnackbar
|
||||
? 70 : 20
|
||||
: -70,
|
||||
right: 20,
|
||||
child: ClientsFab(tab: 1),
|
||||
),
|
||||
child: const ClientsFab(tab: 1),
|
||||
)
|
||||
],
|
||||
);
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
|
@ -13,18 +14,48 @@ import 'package:adguard_home_manager/providers/servers_provider.dart';
|
|||
import 'package:adguard_home_manager/services/http_requests.dart';
|
||||
import 'package:adguard_home_manager/classes/process_modal.dart';
|
||||
|
||||
class BlockedList extends StatelessWidget {
|
||||
class BlockedList extends StatefulWidget {
|
||||
final ScrollController scrollController;
|
||||
final int loadStatus;
|
||||
final List<String> data;
|
||||
final Future Function() fetchClients;
|
||||
|
||||
const BlockedList({
|
||||
Key? key,
|
||||
required this.scrollController,
|
||||
required this.loadStatus,
|
||||
required this.data,
|
||||
required this.fetchClients
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<BlockedList> createState() => _BlockedListState();
|
||||
}
|
||||
|
||||
class _BlockedListState extends State<BlockedList> {
|
||||
late bool isVisible;
|
||||
|
||||
@override
|
||||
initState(){
|
||||
super.initState();
|
||||
|
||||
isVisible = true;
|
||||
widget.scrollController.addListener(() {
|
||||
if (widget.scrollController.position.userScrollDirection == ScrollDirection.reverse) {
|
||||
if (mounted && isVisible == true) {
|
||||
setState(() => isVisible = false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (widget.scrollController.position.userScrollDirection == ScrollDirection.forward) {
|
||||
if (mounted && isVisible == false) {
|
||||
setState(() => isVisible = true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final serversProvider = Provider.of<ServersProvider>(context);
|
||||
|
@ -73,7 +104,7 @@ class BlockedList extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
switch (loadStatus) {
|
||||
switch (widget.loadStatus) {
|
||||
case 0:
|
||||
return SizedBox(
|
||||
width: double.maxFinite,
|
||||
|
@ -98,17 +129,17 @@ class BlockedList extends StatelessWidget {
|
|||
case 1:
|
||||
return Stack(
|
||||
children: [
|
||||
if (data.isNotEmpty) ListView.builder(
|
||||
if (widget.data.isNotEmpty) ListView.builder(
|
||||
padding: const EdgeInsets.only(top: 0),
|
||||
itemCount: data.length,
|
||||
itemCount: widget.data.length,
|
||||
itemBuilder: (context, index) => ListTile(
|
||||
title: Text(data[index]),
|
||||
title: Text(widget.data[index]),
|
||||
trailing: IconButton(
|
||||
onPressed: () => {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => RemoveDomainModal(
|
||||
onConfirm: () => confirmRemoveDomain(data[index]),
|
||||
onConfirm: () => confirmRemoveDomain(widget.data[index]),
|
||||
)
|
||||
)
|
||||
},
|
||||
|
@ -116,13 +147,13 @@ class BlockedList extends StatelessWidget {
|
|||
),
|
||||
)
|
||||
),
|
||||
if (data.isEmpty) SizedBox(
|
||||
if (widget.data.isEmpty) SizedBox(
|
||||
width: double.maxFinite,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context)!.noCustomFilters,
|
||||
AppLocalizations.of(context)!.noBlockedClients,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
|
@ -131,18 +162,23 @@ class BlockedList extends StatelessWidget {
|
|||
),
|
||||
const SizedBox(height: 30),
|
||||
TextButton.icon(
|
||||
onPressed: fetchClients,
|
||||
onPressed: widget.fetchClients,
|
||||
icon: const Icon(Icons.refresh_rounded),
|
||||
label: Text(AppLocalizations.of(context)!.refresh),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
const Positioned(
|
||||
bottom: 20,
|
||||
AnimatedPositioned(
|
||||
duration: const Duration(milliseconds: 100),
|
||||
curve: Curves.easeInOut,
|
||||
bottom: isVisible ?
|
||||
appConfigProvider.showingSnackbar
|
||||
? 70 : 20
|
||||
: -70,
|
||||
right: 20,
|
||||
child: ClientsFab(tab: 2),
|
||||
),
|
||||
child: const ClientsFab(tab: 2),
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:adguard_home_manager/widgets/bottom_nav_bar.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
@ -53,6 +54,7 @@ class ClientsWidget extends StatefulWidget {
|
|||
|
||||
class _ClientsWidgetState extends State<ClientsWidget> with TickerProviderStateMixin {
|
||||
late TabController tabController;
|
||||
final ScrollController scrollController = ScrollController();
|
||||
|
||||
Future fetchClients() async {
|
||||
widget.setLoadingStatus(0, false);
|
||||
|
@ -89,74 +91,10 @@ class _ClientsWidgetState extends State<ClientsWidget> with TickerProviderStateM
|
|||
Widget build(BuildContext context) {
|
||||
final serversProvider = Provider.of<ServersProvider>(context);
|
||||
|
||||
Widget generateBody() {
|
||||
switch (serversProvider.clients.loadStatus) {
|
||||
case 0:
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: double.maxFinite,
|
||||
height: MediaQuery.of(context).size.height-171,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const CircularProgressIndicator(),
|
||||
const SizedBox(height: 30),
|
||||
Text(
|
||||
AppLocalizations.of(context)!.loadingStatus,
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
color: Colors.grey,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
case 1:
|
||||
return Container();
|
||||
|
||||
case 2:
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: double.maxFinite,
|
||||
height: MediaQuery.of(context).size.height-171,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.error,
|
||||
color: Colors.red,
|
||||
size: 50,
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
Text(
|
||||
AppLocalizations.of(context)!.errorLoadServerStatus,
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
color: Colors.grey,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
default:
|
||||
return const SizedBox();
|
||||
}
|
||||
}
|
||||
|
||||
return DefaultTabController(
|
||||
length: 3,
|
||||
child: NestedScrollView(
|
||||
controller: scrollController,
|
||||
headerSliverBuilder: ((context, innerBoxIsScrolled) {
|
||||
return [
|
||||
SliverAppBar(
|
||||
|
@ -201,6 +139,7 @@ class _ClientsWidgetState extends State<ClientsWidget> with TickerProviderStateM
|
|||
RefreshIndicator(
|
||||
onRefresh: fetchClients,
|
||||
child: ClientsList(
|
||||
scrollController: scrollController,
|
||||
loadStatus: serversProvider.clients.loadStatus,
|
||||
data: serversProvider.clients.loadStatus == 1
|
||||
? serversProvider.clients.data!.autoClientsData : [],
|
||||
|
@ -210,6 +149,7 @@ class _ClientsWidgetState extends State<ClientsWidget> with TickerProviderStateM
|
|||
RefreshIndicator(
|
||||
onRefresh: fetchClients,
|
||||
child: AddedList(
|
||||
scrollController: scrollController,
|
||||
loadStatus: serversProvider.clients.loadStatus,
|
||||
data: serversProvider.clients.loadStatus == 1
|
||||
? serversProvider.clients.data!.clients : [],
|
||||
|
@ -219,6 +159,7 @@ class _ClientsWidgetState extends State<ClientsWidget> with TickerProviderStateM
|
|||
RefreshIndicator(
|
||||
onRefresh: fetchClients,
|
||||
child: BlockedList(
|
||||
scrollController: scrollController,
|
||||
loadStatus: serversProvider.clients.loadStatus,
|
||||
data: serversProvider.clients.loadStatus == 1
|
||||
? serversProvider.clients.data!.clientsAllowedBlocked!.disallowedClients : [],
|
||||
|
|
|
@ -4,12 +4,14 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|||
import 'package:adguard_home_manager/models/clients.dart';
|
||||
|
||||
class ClientsList extends StatelessWidget {
|
||||
final ScrollController scrollController;
|
||||
final int loadStatus;
|
||||
final List<AutoClient> data;
|
||||
final Future Function() fetchClients;
|
||||
|
||||
const ClientsList({
|
||||
Key? key,
|
||||
required this.scrollController,
|
||||
required this.loadStatus,
|
||||
required this.data,
|
||||
required this.fetchClients
|
||||
|
|
|
@ -52,6 +52,7 @@ class ClientsFab extends StatelessWidget {
|
|||
blockedHosts: body['blocked_hosts'] ?? [],
|
||||
)
|
||||
);
|
||||
appConfigProvider.setShowingSnackbar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.clientAddedSuccessfully),
|
||||
|
@ -61,6 +62,7 @@ class ClientsFab extends StatelessWidget {
|
|||
}
|
||||
else if (result['result'] == 'error' && result['message'] == 'client_another_list') {
|
||||
appConfigProvider.addLog(result['log']);
|
||||
appConfigProvider.setShowingSnackbar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.clientAnotherList),
|
||||
|
@ -70,6 +72,7 @@ class ClientsFab extends StatelessWidget {
|
|||
}
|
||||
else {
|
||||
appConfigProvider.addLog(result['log']);
|
||||
appConfigProvider.setShowingSnackbar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.clientNotAdded),
|
||||
|
@ -91,6 +94,7 @@ class ClientsFab extends StatelessWidget {
|
|||
ClientsData clientsData = serversProvider.clients.data!;
|
||||
clientsData.clients.add(client);
|
||||
serversProvider.setClientsData(clientsData);
|
||||
appConfigProvider.setShowingSnackbar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.clientAddedSuccessfully),
|
||||
|
@ -100,6 +104,7 @@ class ClientsFab extends StatelessWidget {
|
|||
}
|
||||
else {
|
||||
appConfigProvider.addLog(result['log']);
|
||||
appConfigProvider.setShowingSnackbar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.clientNotAdded),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue