adguard-home-manager/lib/screens/clients/client/identifiers_section.dart

105 lines
3.7 KiB
Dart
Raw Normal View History

2023-11-01 15:43:19 +01:00
import 'package:adguard_home_manager/screens/clients/client/client_screen.dart';
2023-10-07 23:03:30 +02:00
import 'package:flutter/material.dart';
import 'package:uuid/uuid.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:adguard_home_manager/widgets/section_label.dart';
class IdentifiersSection extends StatefulWidget {
2023-11-01 15:43:19 +01:00
final List<ControllerListItem> identifiersControllers;
final void Function(List<ControllerListItem>) onUpdateIdentifiersControllers;
2023-10-07 23:03:30 +02:00
final void Function() onCheckValidValues;
const IdentifiersSection({
super.key,
2023-10-07 23:03:30 +02:00
required this.identifiersControllers,
required this.onUpdateIdentifiersControllers,
required this.onCheckValidValues
});
2023-10-07 23:03:30 +02:00
@override
State<IdentifiersSection> createState() => _IdentifiersSectionState();
}
class _IdentifiersSectionState extends State<IdentifiersSection> {
final Uuid uuid = const Uuid();
@override
Widget build(BuildContext context) {
return Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SectionLabel(
label: AppLocalizations.of(context)!.identifiers,
padding: const EdgeInsets.only(
left: 16, right: 16, top: 24, bottom: 12
2023-10-07 23:03:30 +02:00
)
),
Padding(
padding: const EdgeInsets.only(right: 10),
2023-10-07 23:03:30 +02:00
child: IconButton(
onPressed: () => widget.onUpdateIdentifiersControllers([
...widget.identifiersControllers,
2023-11-01 15:43:19 +01:00
ControllerListItem(
id: uuid.v4(),
controller: TextEditingController()
),
2023-10-07 23:03:30 +02:00
]),
icon: const Icon(Icons.add)
),
)
],
),
if (widget.identifiersControllers.isNotEmpty) ...widget.identifiersControllers.map((controller) => Padding(
2023-11-01 15:43:19 +01:00
padding: const EdgeInsets.only(
top: 12, bottom: 12, left: 16, right: 10
2023-11-01 15:43:19 +01:00
),
2023-10-07 23:03:30 +02:00
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: TextFormField(
2023-11-01 15:43:19 +01:00
controller: controller.controller,
2023-10-07 23:03:30 +02:00
onChanged: (_) => widget.onCheckValidValues(),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.tag),
border: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10)
)
),
helperText: AppLocalizations.of(context)!.identifierHelper,
labelText: AppLocalizations.of(context)!.identifier,
),
),
),
const SizedBox(width: 12),
2023-10-07 23:03:30 +02:00
Padding(
padding: const EdgeInsets.only(bottom: 24),
2023-10-07 23:03:30 +02:00
child: IconButton(
onPressed: () => widget.onUpdateIdentifiersControllers(
2023-11-01 15:43:19 +01:00
widget.identifiersControllers.where((e) => e.id != controller.id).toList()
2023-10-07 23:03:30 +02:00
),
icon: const Icon(Icons.remove_circle_outline_outlined)
),
)
],
),
)),
2023-10-07 23:03:30 +02:00
if (widget.identifiersControllers.isEmpty) Container(
2023-11-01 15:43:19 +01:00
padding: const EdgeInsets.symmetric(vertical: 16),
2023-10-07 23:03:30 +02:00
child: Text(
AppLocalizations.of(context)!.noIdentifiers,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
),
],
);
}
}