mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-04-21 14:29:12 +00:00
Small improvements and refactor
This commit is contained in:
parent
802f2ca328
commit
ed9293fb70
3 changed files with 274 additions and 309 deletions
1
devtools_options.yaml
Normal file
1
devtools_options.yaml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
extensions:
|
|
@ -339,12 +339,19 @@ class _Tab extends StatelessWidget {
|
||||||
Text(text),
|
Text(text),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Container(
|
Container(
|
||||||
width: 18,
|
height: 22,
|
||||||
height: 18,
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 2
|
||||||
|
),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(30),
|
borderRadius: BorderRadius.circular(30),
|
||||||
color: Theme.of(context).colorScheme.primaryContainer
|
color: Theme.of(context).colorScheme.primaryContainer
|
||||||
),
|
),
|
||||||
|
child: ConstrainedBox(
|
||||||
|
constraints: const BoxConstraints(
|
||||||
|
minWidth: 18
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
quantity.toString(),
|
quantity.toString(),
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
|
@ -354,6 +361,8 @@ class _Tab extends StatelessWidget {
|
||||||
color: Theme.of(context).colorScheme.onPrimaryContainer
|
color: Theme.of(context).colorScheme.onPrimaryContainer
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
@ -5,18 +5,9 @@ import 'package:expandable/expandable.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';
|
||||||
|
|
||||||
import 'package:adguard_home_manager/widgets/add_server/add_server_functions.dart';
|
import 'package:adguard_home_manager/widgets/servers_list/server_tile_functions.dart';
|
||||||
import 'package:adguard_home_manager/widgets/servers_list/delete_modal.dart';
|
|
||||||
|
|
||||||
import 'package:adguard_home_manager/models/server_status.dart';
|
|
||||||
import 'package:adguard_home_manager/services/api_client.dart';
|
|
||||||
import 'package:adguard_home_manager/classes/process_modal.dart';
|
|
||||||
import 'package:adguard_home_manager/functions/snackbar.dart';
|
|
||||||
import 'package:adguard_home_manager/constants/enums.dart';
|
|
||||||
import 'package:adguard_home_manager/providers/status_provider.dart';
|
import 'package:adguard_home_manager/providers/status_provider.dart';
|
||||||
import 'package:adguard_home_manager/models/app_log.dart';
|
|
||||||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
|
||||||
import 'package:adguard_home_manager/services/http_requests.dart';
|
|
||||||
import 'package:adguard_home_manager/models/server.dart';
|
import 'package:adguard_home_manager/models/server.dart';
|
||||||
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
||||||
|
|
||||||
|
@ -27,12 +18,12 @@ class ServersListItem extends StatefulWidget {
|
||||||
final void Function(int) onChange;
|
final void Function(int) onChange;
|
||||||
|
|
||||||
const ServersListItem({
|
const ServersListItem({
|
||||||
Key? key,
|
super.key,
|
||||||
required this.expandableController,
|
required this.expandableController,
|
||||||
required this.server,
|
required this.server,
|
||||||
required this.index,
|
required this.index,
|
||||||
required this.onChange
|
required this.onChange
|
||||||
}) : super(key: key);
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<ServersListItem> createState() => _ServersListItemState();
|
State<ServersListItem> createState() => _ServersListItemState();
|
||||||
|
@ -71,94 +62,136 @@ class _ServersListItemState extends State<ServersListItem> with SingleTickerProv
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final serversProvider = Provider.of<ServersProvider>(context);
|
|
||||||
final statusProvider = Provider.of<StatusProvider>(context);
|
|
||||||
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
|
||||||
|
|
||||||
final width = MediaQuery.of(context).size.width;
|
final width = MediaQuery.of(context).size.width;
|
||||||
|
|
||||||
void showDeleteModal(Server server) async {
|
return Container(
|
||||||
await Future.delayed(const Duration(seconds: 0), () => {
|
decoration: BoxDecoration(
|
||||||
showDialog(
|
border: Border(
|
||||||
context: context,
|
bottom: BorderSide(
|
||||||
builder: (context) => DeleteModal(
|
color: Theme.of(context).colorScheme.surfaceVariant,
|
||||||
serverToDelete: server,
|
width: 1
|
||||||
|
)
|
||||||
|
)
|
||||||
),
|
),
|
||||||
barrierDismissible: false
|
child: ExpandableNotifier(
|
||||||
|
controller: widget.expandableController,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Expandable(
|
||||||
|
collapsed: Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: InkWell(
|
||||||
|
onTap: () => widget.onChange(widget.index),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||||
|
child: _TopRow(server: widget.server, animation: animation)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
expanded: Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: InkWell(
|
||||||
|
onTap: () => widget.onChange(widget.index),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
_TopRow(server: widget.server, animation: animation),
|
||||||
|
_BottomRow(
|
||||||
|
server: widget.server,
|
||||||
|
connectToServer: (s) => connectToServer(context: context, server: s),
|
||||||
|
openServerModal: (s) => openServerModal(context: context, server: s, width: width),
|
||||||
|
setDefaultServer: (s) => setDefaultServer(context: context, server: s),
|
||||||
|
showDeleteModal: (s) => showDeleteModal(context: context, server: s),
|
||||||
)
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TopRow extends StatelessWidget {
|
||||||
|
final Server server;
|
||||||
|
final Animation<double> animation;
|
||||||
|
|
||||||
|
const _TopRow({
|
||||||
|
required this.server,
|
||||||
|
required this.animation,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
void openServerModal({Server? server}) async {
|
@override
|
||||||
await Future.delayed(const Duration(seconds: 0), (() => {
|
Widget build(BuildContext context) {
|
||||||
openServerFormModal(context: context, width: width, server: server)
|
return Row(
|
||||||
}));
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
}
|
children: [
|
||||||
|
Expanded(
|
||||||
void connectToServer(Server server) async {
|
child: Row(
|
||||||
final ProcessModal process = ProcessModal();
|
children: [
|
||||||
process.open(AppLocalizations.of(context)!.connecting);
|
Container(
|
||||||
|
margin: const EdgeInsets.only(right: 16),
|
||||||
final result = server.runningOnHa == true
|
child: _LeadingIcon(server: server),
|
||||||
? await loginHA(server)
|
),
|
||||||
: await login(server);
|
Expanded(
|
||||||
|
child: Column(
|
||||||
if (result['result'] == 'success') {
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
final ApiClientV2 apiClient2 = ApiClientV2(server: server);
|
children: [
|
||||||
serversProvider.setApiClient2(apiClient2);
|
Text(
|
||||||
serversProvider.setSelectedServer(server);
|
"${server.connectionMethod}://${server.domain}${server.path ?? ""}${server.port != null ? ':${server.port}' : ""}",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
statusProvider.setServerStatusLoad(LoadStatus.loading);
|
style: TextStyle(
|
||||||
final serverStatus = await apiClient2.getServerStatus();
|
fontSize: 16,
|
||||||
if (serverStatus.successful == true) {
|
fontWeight: FontWeight.w400,
|
||||||
statusProvider.setServerStatusData(
|
color: Theme.of(context).colorScheme.onSurface
|
||||||
data: serverStatus.content as ServerStatus
|
),
|
||||||
);
|
),
|
||||||
serversProvider.checkServerUpdatesAvailable(
|
Column(
|
||||||
server: server,
|
children: [
|
||||||
);
|
const SizedBox(height: 3),
|
||||||
statusProvider.setServerStatusLoad(LoadStatus.loaded);
|
Text(
|
||||||
}
|
server.name,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
process.close();
|
style: TextStyle(
|
||||||
}
|
fontSize: 14,
|
||||||
else {
|
fontWeight: FontWeight.w400,
|
||||||
process.close();
|
color: Theme.of(context).colorScheme.onSurfaceVariant
|
||||||
appConfigProvider.addLog(result['log']);
|
),
|
||||||
showSnacbkar(
|
|
||||||
appConfigProvider: appConfigProvider,
|
|
||||||
label: AppLocalizations.of(context)!.cannotConnect,
|
|
||||||
color: Colors.red
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDefaultServer(Server server) async {
|
|
||||||
final result = await serversProvider.setDefaultServer(server);
|
|
||||||
if (result == null) {
|
|
||||||
showSnacbkar(
|
|
||||||
appConfigProvider: appConfigProvider,
|
|
||||||
label: AppLocalizations.of(context)!.connectionDefaultSuccessfully,
|
|
||||||
color: Colors.green
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
appConfigProvider.addLog(
|
|
||||||
AppLog(
|
|
||||||
type: 'set_default_server',
|
|
||||||
dateTime: DateTime.now(),
|
|
||||||
message: result.toString()
|
|
||||||
)
|
)
|
||||||
);
|
],
|
||||||
showSnacbkar(
|
)
|
||||||
appConfigProvider: appConfigProvider,
|
],
|
||||||
label: AppLocalizations.of(context)!.connectionDefaultFailed,
|
),
|
||||||
color: Colors.red
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
RotationTransition(
|
||||||
|
turns: animation,
|
||||||
|
child: const Icon(Icons.keyboard_arrow_down_rounded),
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget leadingIcon(Server server) {
|
class _LeadingIcon extends StatelessWidget {
|
||||||
|
final Server server;
|
||||||
|
|
||||||
|
const _LeadingIcon({
|
||||||
|
required this.server,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final serversProvider = Provider.of<ServersProvider>(context);
|
||||||
|
final statusProvider = Provider.of<StatusProvider>(context);
|
||||||
|
|
||||||
if (server.defaultServer == true) {
|
if (server.defaultServer == true) {
|
||||||
return Stack(
|
return Stack(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
|
@ -206,60 +239,28 @@ class _ServersListItemState extends State<ServersListItem> with SingleTickerProv
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget topRow(Server server, int index) {
|
|
||||||
return Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
margin: const EdgeInsets.only(right: 16),
|
|
||||||
child: leadingIcon(server),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"${server.connectionMethod}://${server.domain}${server.path ?? ""}${server.port != null ? ':${server.port}' : ""}",
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.w400,
|
|
||||||
color: Theme.of(context).colorScheme.onSurface
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
const SizedBox(height: 3),
|
|
||||||
Text(
|
|
||||||
server.name,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w400,
|
|
||||||
color: Theme.of(context).colorScheme.onSurfaceVariant
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
RotationTransition(
|
|
||||||
turns: animation,
|
|
||||||
child: const Icon(Icons.keyboard_arrow_down_rounded),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget bottomRow(Server server, int index) {
|
class _BottomRow extends StatelessWidget {
|
||||||
|
final Server server;
|
||||||
|
final void Function(Server) setDefaultServer;
|
||||||
|
final void Function(Server) openServerModal;
|
||||||
|
final void Function(Server) showDeleteModal;
|
||||||
|
final void Function(Server) connectToServer;
|
||||||
|
|
||||||
|
const _BottomRow({
|
||||||
|
required this.server,
|
||||||
|
required this.setDefaultServer,
|
||||||
|
required this.openServerModal,
|
||||||
|
required this.showDeleteModal,
|
||||||
|
required this.connectToServer,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final serversProvider = Provider.of<ServersProvider>(context);
|
||||||
|
final statusProvider = Provider.of<StatusProvider>(context);
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
|
@ -291,7 +292,7 @@ class _ServersListItemState extends State<ServersListItem> with SingleTickerProv
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
onTap: (() => openServerModal(server: server)),
|
onTap: (() => openServerModal(server)),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.edit),
|
const Icon(Icons.edit),
|
||||||
|
@ -357,50 +358,4 @@ class _ServersListItemState extends State<ServersListItem> with SingleTickerProv
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
border: Border(
|
|
||||||
bottom: BorderSide(
|
|
||||||
color: Theme.of(context).colorScheme.surfaceVariant,
|
|
||||||
width: 1
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
child: ExpandableNotifier(
|
|
||||||
controller: widget.expandableController,
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
Expandable(
|
|
||||||
collapsed: Material(
|
|
||||||
color: Colors.transparent,
|
|
||||||
child: InkWell(
|
|
||||||
onTap: () => widget.onChange(widget.index),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
||||||
child: topRow(widget.server, widget.index),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
expanded: Material(
|
|
||||||
color: Colors.transparent,
|
|
||||||
child: InkWell(
|
|
||||||
onTap: () => widget.onChange(widget.index),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
topRow(widget.server, widget.index),
|
|
||||||
bottomRow(widget.server, widget.index)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue