2022-10-06 00:47:35 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
|
2022-10-09 01:13:55 +02:00
|
|
|
class AddClientModal extends StatefulWidget {
|
|
|
|
final String type;
|
|
|
|
final void Function(String, String) onConfirm;
|
2022-10-06 00:47:35 +02:00
|
|
|
|
2022-10-09 01:13:55 +02:00
|
|
|
const AddClientModal({
|
2022-10-06 00:47:35 +02:00
|
|
|
Key? key,
|
2022-10-09 01:13:55 +02:00
|
|
|
required this.type,
|
2022-10-06 00:47:35 +02:00
|
|
|
required this.onConfirm
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
2022-10-09 01:13:55 +02:00
|
|
|
State<AddClientModal> createState() => _AddClientModalState();
|
2022-10-06 00:47:35 +02:00
|
|
|
}
|
|
|
|
|
2022-10-09 01:13:55 +02:00
|
|
|
class _AddClientModalState extends State<AddClientModal> {
|
|
|
|
TextEditingController fieldController = TextEditingController();
|
2022-10-06 00:47:35 +02:00
|
|
|
|
2022-10-09 01:13:55 +02:00
|
|
|
bool validData = false;
|
2022-10-06 00:47:35 +02:00
|
|
|
|
2022-10-09 01:13:55 +02:00
|
|
|
void checkValidValues() {
|
|
|
|
if (fieldController.text != '') {
|
|
|
|
setState(() => validData = true);
|
2022-10-06 00:47:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2022-10-09 01:13:55 +02:00
|
|
|
setState(() => validData = false);
|
2022-10-06 00:47:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-10-09 01:13:55 +02:00
|
|
|
IconData icon() {
|
|
|
|
switch (widget.type) {
|
|
|
|
case 'allowed':
|
|
|
|
return Icons.check;
|
|
|
|
|
|
|
|
case 'disallowed':
|
|
|
|
return Icons.block;
|
|
|
|
|
|
|
|
case 'domains':
|
|
|
|
return Icons.link_rounded;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return Icons.check;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String title() {
|
|
|
|
switch (widget.type) {
|
|
|
|
case 'allowed':
|
|
|
|
return AppLocalizations.of(context)!.allowClient;
|
|
|
|
|
|
|
|
case 'disallowed':
|
|
|
|
return AppLocalizations.of(context)!.disallowClient;
|
|
|
|
|
|
|
|
case 'domains':
|
|
|
|
return AppLocalizations.of(context)!.disallowedDomains;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-06 00:47:35 +02:00
|
|
|
return Padding(
|
|
|
|
padding: MediaQuery.of(context).viewInsets,
|
|
|
|
child: Container(
|
|
|
|
height: 322,
|
|
|
|
padding: const EdgeInsets.all(28),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context).dialogBackgroundColor,
|
|
|
|
borderRadius: const BorderRadius.only(
|
|
|
|
topLeft: Radius.circular(28),
|
|
|
|
topRight: Radius.circular(28)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
2022-10-09 01:13:55 +02:00
|
|
|
Icon(
|
|
|
|
icon(),
|
2022-10-06 00:47:35 +02:00
|
|
|
size: 26,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
Text(
|
2022-10-09 01:13:55 +02:00
|
|
|
title(),
|
2022-10-06 00:47:35 +02:00
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 24
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 30),
|
|
|
|
TextFormField(
|
2022-10-09 01:13:55 +02:00
|
|
|
controller: fieldController,
|
|
|
|
onChanged: (_) => checkValidValues(),
|
2022-10-06 00:47:35 +02:00
|
|
|
decoration: InputDecoration(
|
|
|
|
prefixIcon: const Icon(Icons.link_rounded),
|
|
|
|
border: const OutlineInputBorder(
|
|
|
|
borderRadius: BorderRadius.all(
|
|
|
|
Radius.circular(10)
|
|
|
|
)
|
|
|
|
),
|
2022-10-09 01:13:55 +02:00
|
|
|
helperText: widget.type == 'allowed' || widget.type == 'blocked'
|
|
|
|
? AppLocalizations.of(context)!.addClientFieldDescription : null,
|
|
|
|
labelText: widget.type == 'allowed' || widget.type == 'blocked'
|
|
|
|
? AppLocalizations.of(context)!.clientIdentifier
|
|
|
|
: AppLocalizations.of(context)!.domain,
|
2022-10-06 00:47:35 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 20),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
child: Text(AppLocalizations.of(context)!.cancel)
|
|
|
|
),
|
|
|
|
const SizedBox(width: 20),
|
|
|
|
TextButton(
|
2022-10-09 01:13:55 +02:00
|
|
|
onPressed: validData == true
|
2022-10-06 00:47:35 +02:00
|
|
|
? () {
|
|
|
|
Navigator.pop(context);
|
2022-10-09 01:13:55 +02:00
|
|
|
widget.onConfirm(fieldController.text, widget.type);
|
2022-10-06 00:47:35 +02:00
|
|
|
}
|
|
|
|
: null,
|
|
|
|
child: Text(
|
|
|
|
AppLocalizations.of(context)!.confirm,
|
|
|
|
style: TextStyle(
|
2022-10-09 01:13:55 +02:00
|
|
|
color: validData == true
|
2022-10-06 00:47:35 +02:00
|
|
|
? Theme.of(context).primaryColor
|
|
|
|
: Colors.grey
|
|
|
|
),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|