2023-04-30 23:36:02 +02:00
|
|
|
import 'dart:io';
|
|
|
|
|
2022-10-09 01:13:55 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
|
2022-10-10 01:26:33 +02:00
|
|
|
import 'package:adguard_home_manager/screens/settings/access_settings/clients_list.dart';
|
2022-10-09 01:13:55 +02:00
|
|
|
|
2023-10-29 02:47:14 +01:00
|
|
|
import 'package:adguard_home_manager/functions/desktop_mode.dart';
|
2023-04-06 18:50:06 +02:00
|
|
|
import 'package:adguard_home_manager/constants/enums.dart';
|
2023-05-24 14:16:53 +02:00
|
|
|
import 'package:adguard_home_manager/providers/clients_provider.dart';
|
2022-10-09 01:13:55 +02:00
|
|
|
|
2023-05-24 14:16:53 +02:00
|
|
|
class AccessSettings extends StatefulWidget {
|
2023-11-19 04:56:51 +01:00
|
|
|
const AccessSettings({super.key});
|
2022-10-09 01:13:55 +02:00
|
|
|
|
|
|
|
@override
|
2023-05-24 14:16:53 +02:00
|
|
|
State<AccessSettings> createState() => _AccessSettingsState();
|
2022-10-09 01:13:55 +02:00
|
|
|
}
|
|
|
|
|
2023-05-24 14:16:53 +02:00
|
|
|
class _AccessSettingsState extends State<AccessSettings> with TickerProviderStateMixin {
|
2023-11-19 04:56:51 +01:00
|
|
|
late ScrollController _scrollController;
|
|
|
|
late TabController _tabController;
|
2022-10-09 01:13:55 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
2023-05-25 15:06:21 +02:00
|
|
|
Provider.of<ClientsProvider>(context, listen: false).fetchClients(updateLoading: true);
|
2022-10-09 01:13:55 +02:00
|
|
|
super.initState();
|
2023-11-19 04:56:51 +01:00
|
|
|
_tabController = TabController(
|
2022-10-09 01:13:55 +02:00
|
|
|
initialIndex: 0,
|
|
|
|
length: 3,
|
|
|
|
vsync: this,
|
|
|
|
);
|
2023-11-19 04:56:51 +01:00
|
|
|
_scrollController = ScrollController();
|
2022-10-09 01:13:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-10-29 02:47:14 +01:00
|
|
|
final width = MediaQuery.of(context).size.width;
|
|
|
|
|
2023-04-30 23:36:02 +02:00
|
|
|
if (Platform.isAndroid || Platform.isIOS) {
|
|
|
|
return Scaffold(
|
|
|
|
body: DefaultTabController(
|
|
|
|
length: 3,
|
|
|
|
child: NestedScrollView(
|
2023-11-19 04:56:51 +01:00
|
|
|
controller: _scrollController,
|
2023-04-30 23:36:02 +02:00
|
|
|
headerSliverBuilder: ((context, innerBoxIsScrolled) {
|
|
|
|
return [
|
|
|
|
SliverOverlapAbsorber(
|
|
|
|
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
|
|
|
sliver: SliverSafeArea(
|
|
|
|
top: false,
|
2023-12-14 15:22:09 +01:00
|
|
|
bottom: false,
|
2023-04-30 23:36:02 +02:00
|
|
|
sliver: SliverAppBar(
|
|
|
|
title: Text(AppLocalizations.of(context)!.accessSettings),
|
|
|
|
pinned: true,
|
|
|
|
floating: true,
|
|
|
|
centerTitle: false,
|
|
|
|
forceElevated: innerBoxIsScrolled,
|
2023-10-29 02:47:14 +01:00
|
|
|
surfaceTintColor: isDesktop(width) ? Colors.transparent : null,
|
2023-12-14 15:22:09 +01:00
|
|
|
bottom: _Tabs(tabController: _tabController)
|
2023-04-30 23:36:02 +02:00
|
|
|
),
|
2022-10-09 16:44:58 +02:00
|
|
|
),
|
2023-04-30 23:36:02 +02:00
|
|
|
)
|
|
|
|
];
|
|
|
|
}),
|
2023-11-19 04:56:51 +01:00
|
|
|
body: _TabsView(
|
|
|
|
tabController: _tabController,
|
|
|
|
scrollController: _scrollController
|
|
|
|
)
|
2023-03-16 23:29:18 +01:00
|
|
|
)
|
2023-04-30 23:36:02 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(AppLocalizations.of(context)!.accessSettings),
|
|
|
|
centerTitle: false,
|
2023-11-19 04:56:51 +01:00
|
|
|
bottom: PreferredSize(
|
|
|
|
preferredSize: const Size(double.maxFinite, 50),
|
|
|
|
child: _Tabs(tabController: _tabController)
|
|
|
|
)
|
2023-04-30 23:36:02 +02:00
|
|
|
),
|
2023-11-19 04:56:51 +01:00
|
|
|
body: _TabsView(
|
|
|
|
tabController: _tabController,
|
|
|
|
scrollController: _scrollController
|
|
|
|
)
|
2023-04-30 23:36:02 +02:00
|
|
|
);
|
|
|
|
}
|
2022-10-09 01:13:55 +02:00
|
|
|
}
|
2023-11-19 04:56:51 +01:00
|
|
|
}
|
|
|
|
|
2023-12-14 15:22:09 +01:00
|
|
|
class _Tabs extends StatelessWidget implements PreferredSizeWidget {
|
2023-11-19 04:56:51 +01:00
|
|
|
final TabController tabController;
|
|
|
|
|
|
|
|
const _Tabs({
|
|
|
|
required this.tabController,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return TabBar(
|
|
|
|
controller: tabController,
|
|
|
|
isScrollable: true,
|
|
|
|
unselectedLabelColor: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
|
|
tabAlignment: TabAlignment.start,
|
|
|
|
tabs: [
|
|
|
|
Tab(
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
const Icon(Icons.check),
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
Text(AppLocalizations.of(context)!.allowedClients)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Tab(
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
const Icon(Icons.block),
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
Text(AppLocalizations.of(context)!.disallowedClients)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Tab(
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
const Icon(Icons.link_rounded),
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
Text(AppLocalizations.of(context)!.disallowedDomains)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
2023-12-14 15:22:09 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
2023-11-19 04:56:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class _TabsView extends StatelessWidget {
|
|
|
|
final TabController tabController;
|
|
|
|
final ScrollController scrollController;
|
|
|
|
|
|
|
|
const _TabsView({
|
|
|
|
required this.tabController,
|
|
|
|
required this.scrollController,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final clientsProvider = Provider.of<ClientsProvider>(context);
|
|
|
|
|
|
|
|
return TabBarView(
|
|
|
|
controller: tabController,
|
|
|
|
children: [
|
|
|
|
ClientsList(
|
|
|
|
type: AccessSettingsList.allowed,
|
|
|
|
scrollController: scrollController,
|
|
|
|
loadStatus: clientsProvider.loadStatus,
|
|
|
|
data: clientsProvider.loadStatus == LoadStatus.loaded
|
|
|
|
? clientsProvider.clients!.clientsAllowedBlocked!.allowedClients : [],
|
|
|
|
),
|
|
|
|
ClientsList(
|
|
|
|
type: AccessSettingsList.disallowed,
|
|
|
|
scrollController: scrollController,
|
|
|
|
loadStatus: clientsProvider.loadStatus,
|
|
|
|
data: clientsProvider.loadStatus == LoadStatus.loaded
|
|
|
|
? clientsProvider.clients!.clientsAllowedBlocked!.disallowedClients : [],
|
|
|
|
),
|
|
|
|
ClientsList(
|
|
|
|
type: AccessSettingsList.domains,
|
|
|
|
scrollController: scrollController,
|
|
|
|
loadStatus: clientsProvider.loadStatus,
|
|
|
|
data: clientsProvider.loadStatus == LoadStatus.loaded
|
|
|
|
? clientsProvider.clients!.clientsAllowedBlocked!.blockedHosts : [],
|
|
|
|
),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
2022-10-09 01:13:55 +02:00
|
|
|
}
|