Modified dhcp leases

This commit is contained in:
Juan Gilsanz Polo 2022-10-24 01:30:56 +02:00
parent c3690902c8
commit 1832d3d374
2 changed files with 74 additions and 71 deletions

View file

@ -6,7 +6,7 @@ import 'package:bottom_sheet/bottom_sheet.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/section_label.dart'; import 'package:adguard_home_manager/screens/settings/section_label.dart';
import 'package:adguard_home_manager/screens/settings/dhcp/dhcp_static.dart'; import 'package:adguard_home_manager/screens/settings/dhcp/dhcp_leases.dart';
import 'package:adguard_home_manager/screens/settings/dhcp/select_interface_modal.dart'; import 'package:adguard_home_manager/screens/settings/dhcp/select_interface_modal.dart';
import 'package:adguard_home_manager/functions/snackbar.dart'; import 'package:adguard_home_manager/functions/snackbar.dart';
@ -601,60 +601,47 @@ class _DhcpWidgetState extends State<DhcpWidget> {
), ),
), ),
], ],
const SizedBox(height: 20),
SectionLabel( SectionLabel(
label: AppLocalizations.of(context)!.dhcpLeases, label: AppLocalizations.of(context)!.dhcpLeases,
), ),
if (serversProvider.dhcp.data!.dhcpStatus.leases.isNotEmpty) ListView.builder(
padding: const EdgeInsets.only(top: 0),
itemCount: serversProvider.dhcp.data!.dhcpStatus.leases.length,
itemBuilder: (context, index) => Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
child: Column(
children: [
Text(
serversProvider.dhcp.data!.dhcpStatus.leases[index].ip,
style: const TextStyle(
fontWeight: FontWeight.w500
),
),
const SizedBox(height: 3),
Text(
serversProvider.dhcp.data!.dhcpStatus.leases[index].mac,
style: const TextStyle(
color: Colors.grey,
fontSize: 14
),
),
const SizedBox(height: 3),
Text(
serversProvider.dhcp.data!.dhcpStatus.leases[index].hostname,
style: const TextStyle(
fontSize: 14
),
),
],
),
)
),
if (serversProvider.dhcp.data!.dhcpStatus.leases.isEmpty) Container(
padding: const EdgeInsets.symmetric(horizontal: 28),
child: Text(
AppLocalizations.of(context)!.noLeases,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 18,
color: Colors.grey
),
),
),
const SizedBox(height: 20),
Material( Material(
color: Colors.transparent, color: Colors.transparent,
child: InkWell( child: InkWell(
onTap: () { onTap: () {
Navigator.push(context, MaterialPageRoute( Navigator.push(context, MaterialPageRoute(
builder: (context) => DhcpStatic( builder: (context) => DhcpLeases(
items: serversProvider.dhcp.data!.dhcpStatus.staticLeases items: serversProvider.dhcp.data!.dhcpStatus.leases,
staticLeases: false,
)
));
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 28, vertical: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
AppLocalizations.of(context)!.dhcpLeases,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 16
),
),
const Icon(Icons.arrow_forward_rounded)
],
),
),
),
),
Material(
color: Colors.transparent,
child: InkWell(
onTap: () {
Navigator.push(context, MaterialPageRoute(
builder: (context) => DhcpLeases(
items: serversProvider.dhcp.data!.dhcpStatus.staticLeases,
staticLeases: true,
) )
)); ));
}, },
@ -676,6 +663,7 @@ class _DhcpWidgetState extends State<DhcpWidget> {
), ),
), ),
), ),
const SizedBox(height: 10)
], ],
); );
} }

View file

@ -15,12 +15,14 @@ import 'package:adguard_home_manager/classes/process_modal.dart';
import 'package:adguard_home_manager/models/dhcp.dart'; import 'package:adguard_home_manager/models/dhcp.dart';
import 'package:adguard_home_manager/providers/servers_provider.dart'; import 'package:adguard_home_manager/providers/servers_provider.dart';
class DhcpStatic extends StatelessWidget { class DhcpLeases extends StatelessWidget {
final List<Lease> items; final List<Lease> items;
final bool staticLeases;
const DhcpStatic({ const DhcpLeases({
Key? key, Key? key,
required this.items, required this.items,
required this.staticLeases,
}) : super(key: key); }) : super(key: key);
@override @override
@ -129,7 +131,11 @@ class DhcpStatic extends StatelessWidget {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(AppLocalizations.of(context)!.dhcpStatic), title: Text(
staticLeases == true
? AppLocalizations.of(context)!.dhcpStatic
: AppLocalizations.of(context)!.dhcpLeases,
),
), ),
body: items.isNotEmpty body: items.isNotEmpty
? ListView.builder( ? ListView.builder(
@ -145,33 +151,42 @@ class DhcpStatic extends StatelessWidget {
Text(items[index].hostname), Text(items[index].hostname),
], ],
), ),
trailing: IconButton( trailing: staticLeases == true
onPressed: () { ? IconButton(
showModal( onPressed: () {
context: context, showModal(
builder: (context) => DeleteStaticLeaseModal( context: context,
onConfirm: () => deleteLease(items[index]) builder: (context) => DeleteStaticLeaseModal(
) onConfirm: () => deleteLease(items[index])
); )
}, );
icon: const Icon(Icons.delete) },
), icon: const Icon(Icons.delete)
)
: null,
), ),
) )
: Center( : Center(
child: Text( child: Padding(
AppLocalizations.of(context)!.noDhcpStaticLeases, padding: const EdgeInsets.all(10),
textAlign: TextAlign.center, child: Text(
style: const TextStyle( staticLeases == true
color: Colors.grey, ? AppLocalizations.of(context)!.noDhcpStaticLeases
fontSize: 22 : AppLocalizations.of(context)!.noLeases,
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.grey,
fontSize: 22
),
), ),
), ),
), ),
floatingActionButton: FloatingActionButton( floatingActionButton: staticLeases == true
onPressed: openAddStaticLease, ? FloatingActionButton(
child: const Icon(Icons.add), onPressed: openAddStaticLease,
), child: const Icon(Icons.add),
)
: null,
); );
} }
} }