Updated dhcp interfaces list

This commit is contained in:
Juan Gilsanz Polo 2023-10-08 21:46:18 +02:00
parent ddd0fe177b
commit f84b217d91
3 changed files with 266 additions and 190 deletions

View file

@ -345,7 +345,9 @@ class _DhcpScreenState extends State<DhcpScreen> {
}), }),
dialog: false, dialog: false,
), ),
isScrollControlled: true isScrollControlled: true,
useSafeArea: true,
backgroundColor: Colors.transparent
); );
} }
}); });

View file

@ -0,0 +1,136 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:adguard_home_manager/models/dhcp.dart';
class DhcpInterfaceItem extends StatelessWidget {
final NetworkInterface networkInterface;
final void Function(NetworkInterface) onSelect;
const DhcpInterfaceItem({
Key? key,
required this.networkInterface,
required this.onSelect
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Material(
color: Colors.transparent,
child: InkWell(
onTap: () {
Navigator.pop(context);
onSelect(networkInterface);
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
networkInterface.name,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
color: Theme.of(context).colorScheme.onSurface
),
),
Row(
children: [
Text(
"${AppLocalizations.of(context)!.hardwareAddress}: ",
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant
),
),
Text(
networkInterface.hardwareAddress,
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant
),
),
],
),
const SizedBox(height: 5),
if (networkInterface.flags.isNotEmpty) ...[
Row(
children: [
Text(
"Flags: ",
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant
),
),
Text(
networkInterface.flags.join(', '),
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant
),
),
],
),
const SizedBox(height: 5),
],
if (networkInterface.gatewayIp != null && networkInterface.gatewayIp != '') ...[
Row(
children: [
Text(
"${AppLocalizations.of(context)!.gatewayIp}: ",
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant
),
),
Text(
networkInterface.gatewayIp!,
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant
),
),
],
),
const SizedBox(height: 5),
],
if (networkInterface.ipv4Addresses.isNotEmpty) ...[
Row(
children: [
Flexible(
child: Text(
"${AppLocalizations.of(context)!.ipv4addresses}: ${networkInterface.ipv4Addresses.join(', ')}",
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant
),
),
)
],
),
const SizedBox(height: 5),
],
if (networkInterface.ipv6Addresses.isNotEmpty) ...[
Row(
children: [
Flexible(
child: Text(
"${AppLocalizations.of(context)!.ipv6addresses}: ${networkInterface.ipv6Addresses.join(', ')}",
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant
),
),
)
],
),
]
],
),
),
),
);
}
}

View file

@ -3,6 +3,8 @@ import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:adguard_home_manager/screens/settings/dhcp/dhcp_interface_item.dart';
import 'package:adguard_home_manager/models/dhcp.dart'; import 'package:adguard_home_manager/models/dhcp.dart';
class SelectInterfaceModal extends StatelessWidget { class SelectInterfaceModal extends StatelessWidget {
@ -19,12 +21,17 @@ class SelectInterfaceModal extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Widget content() { if (dialog == true) {
return Column( return Dialog(
child: ConstrainedBox(
constraints: const BoxConstraints(
maxWidth: 500,
),
child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Flexible( Padding(
child: SingleChildScrollView( padding: const EdgeInsets.all(16),
child: Wrap( child: Wrap(
children: [ children: [
Row( Row(
@ -32,14 +39,11 @@ class SelectInterfaceModal extends StatelessWidget {
children: [ children: [
Column( Column(
children: [ children: [
Padding( Icon(
padding: const EdgeInsets.only(top: 24),
child: Icon(
Icons.settings_ethernet_rounded, Icons.settings_ethernet_rounded,
size: 24, size: 24,
color: Theme.of(context).listTileTheme.iconColor color: Theme.of(context).listTileTheme.iconColor
), ),
),
const SizedBox(height: 16), const SizedBox(height: 16),
Text( Text(
AppLocalizations.of(context)!.selectInterface, AppLocalizations.of(context)!.selectInterface,
@ -54,130 +58,16 @@ class SelectInterfaceModal extends StatelessWidget {
], ],
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
ListView.builder( ],
primary: false, ),
shrinkWrap: true, ),
Expanded(
child: ListView.builder(
itemCount: interfaces.length, itemCount: interfaces.length,
itemBuilder: (context, index) => Material( itemBuilder: (context, index) => DhcpInterfaceItem(
color: Colors.transparent, networkInterface: interfaces[index],
child: InkWell( onSelect: onSelect
onTap: () {
Navigator.pop(context);
onSelect(interfaces[index]);
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
interfaces[index].name,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
color: Theme.of(context).colorScheme.onSurface
),
),
Row(
children: [
Text(
"${AppLocalizations.of(context)!.hardwareAddress}: ",
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant
),
),
Text(
interfaces[index].hardwareAddress,
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant
),
),
],
),
const SizedBox(height: 5),
if (interfaces[index].flags.isNotEmpty) ...[
Row(
children: [
Text(
"Flags: ",
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant
),
),
Text(
interfaces[index].flags.join(', '),
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant
),
),
],
),
const SizedBox(height: 5),
],
if (interfaces[index].gatewayIp != null && interfaces[index].gatewayIp != '') ...[
Row(
children: [
Text(
"${AppLocalizations.of(context)!.gatewayIp}: ",
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant
),
),
Text(
interfaces[index].gatewayIp!,
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant
),
),
],
),
const SizedBox(height: 5),
],
if (interfaces[index].ipv4Addresses.isNotEmpty) ...[
Row(
children: [
Flexible(
child: Text(
"${AppLocalizations.of(context)!.ipv4addresses}: ${interfaces[index].ipv4Addresses.join(', ')}",
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant
),
),
) )
],
),
const SizedBox(height: 5),
],
if (interfaces[index].ipv6Addresses.isNotEmpty) ...[
Row(
children: [
Flexible(
child: Text(
"${AppLocalizations.of(context)!.ipv6addresses}: ${interfaces[index].ipv6Addresses.join(', ')}",
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant
),
),
)
],
),
]
],
),
),
),
)
),
],
),
), ),
), ),
Padding( Padding(
@ -194,29 +84,77 @@ class SelectInterfaceModal extends StatelessWidget {
), ),
if (Platform.isIOS) const SizedBox(height: 16) if (Platform.isIOS) const SizedBox(height: 16)
], ],
);
}
if (dialog == true) {
return Dialog(
child: ConstrainedBox(
constraints: const BoxConstraints(
maxWidth: 500
), ),
child: content()
), ),
); );
} }
else { else {
return GestureDetector(
onTap: () => Navigator.of(context).pop(),
child: Container(
color: Colors.transparent,
child: DraggableScrollableSheet(
initialChildSize: 0.6,
minChildSize: 0.3,
maxChildSize: 1,
builder: (context, controller) {
return Container( return Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context).dialogBackgroundColor, color: Theme.of(context).colorScheme.surface,
borderRadius: const BorderRadius.only( borderRadius: const BorderRadius.only(
topLeft: Radius.circular(28), topLeft: Radius.circular(28),
topRight: Radius.circular(28) topRight: Radius.circular(28),
),
),
child: Column(
children: [
Container(
margin: const EdgeInsets.all(16),
width: 36,
height: 4,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.grey
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: Column(
children: [
Icon(
Icons.settings_ethernet_rounded,
size: 24,
color: Theme.of(context).listTileTheme.iconColor
),
const SizedBox(height: 16),
Text(
AppLocalizations.of(context)!.selectInterface,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 24,
color: Theme.of(context).colorScheme.onSurface
),
),
],
),
),
Expanded(
child: ListView.builder(
controller: controller,
itemCount: interfaces.length,
itemBuilder: (context, index) => DhcpInterfaceItem(
networkInterface: interfaces[index],
onSelect: onSelect
)
) )
), ),
child: content() const SizedBox(height: 16)
],
),
);
},
),
),
); );
} }
} }