adguard-home-manager/lib/screens/settings/dhcp/select_interface_modal.dart

158 lines
5.3 KiB
Dart
Raw Normal View History

2023-03-16 23:29:18 +01:00
import 'dart:io';
2022-10-12 03:58:17 +02:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2023-10-08 21:46:18 +02:00
import 'package:adguard_home_manager/screens/settings/dhcp/dhcp_interface_item.dart';
2022-10-12 03:58:17 +02:00
import 'package:adguard_home_manager/models/dhcp.dart';
class SelectInterfaceModal extends StatelessWidget {
final List<NetworkInterface> interfaces;
final void Function(NetworkInterface) onSelect;
2023-05-01 02:50:42 +02:00
final bool dialog;
2022-10-12 03:58:17 +02:00
const SelectInterfaceModal({
Key? key,
required this.interfaces,
required this.onSelect,
2023-05-01 02:50:42 +02:00
required this.dialog
2022-10-12 03:58:17 +02:00
}) : super(key: key);
@override
Widget build(BuildContext context) {
2023-10-08 21:46:18 +02:00
if (dialog == true) {
return Dialog(
child: ConstrainedBox(
constraints: const BoxConstraints(
maxWidth: 500,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.all(16),
child: Wrap(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Column(
children: [
Icon(
2023-05-01 04:49:40 +02:00
Icons.settings_ethernet_rounded,
size: 24,
color: Theme.of(context).listTileTheme.iconColor
),
2023-10-08 21:46:18 +02:00
const SizedBox(height: 16),
Text(
AppLocalizations.of(context)!.selectInterface,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 24,
color: Theme.of(context).colorScheme.onSurface
2023-05-01 04:49:40 +02:00
),
2022-10-12 03:58:17 +02:00
),
2023-10-08 21:46:18 +02:00
],
),
2023-10-08 21:46:18 +02:00
],
),
const SizedBox(height: 16),
],
),
),
Expanded(
child: ListView.builder(
itemCount: interfaces.length,
itemBuilder: (context, index) => DhcpInterfaceItem(
networkInterface: interfaces[index],
onSelect: onSelect
)
),
),
Padding(
padding: const EdgeInsets.all(20),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(AppLocalizations.of(context)!.cancel)
2023-05-01 04:49:40 +02:00
)
2023-10-08 21:46:18 +02:00
],
),
2023-05-01 04:49:40 +02:00
),
2023-10-08 21:46:18 +02:00
if (Platform.isIOS) const SizedBox(height: 16)
],
2023-03-16 23:29:18 +01:00
),
2023-05-01 02:50:42 +02:00
),
);
}
else {
2023-10-08 21:46:18 +02:00
return GestureDetector(
2023-11-01 20:46:03 +01:00
onTap: () => Navigator.of(context).pop(),
2023-10-08 21:46:18 +02:00
child: DraggableScrollableSheet(
initialChildSize: 0.6,
minChildSize: 0.3,
maxChildSize: 1,
builder: (context, controller) {
return Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
borderRadius: const BorderRadius.only(
topLeft: 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
)
)
),
const SizedBox(height: 16)
],
),
);
},
2023-05-01 02:50:42 +02:00
),
2023-11-01 20:46:03 +01:00
);
2023-05-01 02:50:42 +02:00
}
2022-10-12 03:58:17 +02:00
}
}