You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

76 lines
2.9 KiB

import 'package:counters/counters.dart';
import 'package:counters/datbase.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class UpdateCounterPage extends StatelessWidget {
UpdateCounterPage({super.key, required this.counter});
final Counter counter;
final nameController = TextEditingController();
final dropdownController = TextEditingController();
CounterType counterType = CounterType.coldWater;
@override
@override
Widget build(BuildContext context) {
nameController.text = counter.name;
counterType = counter.counterType;
dropdownController.text = counter.counterType.getLabel(context);
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(AppLocalizations.of(context)!.new_counter_title)),
body: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
DropdownMenu<CounterType>(
controller: dropdownController,
enableFilter: true,
hintText:
AppLocalizations.of(context)!.choose_type_of_counter,
expandedInsets: EdgeInsets.zero,
dropdownMenuEntries:
CounterType.values.map<DropdownMenuEntry<CounterType>>(
(CounterType icon) {
return DropdownMenuEntry<CounterType>(
value: icon,
labelWidget: Text(icon.getLabel(context)),
label: icon.getLabel(context)
//leadingIcon: Icon(icon.icon),
);
},
).toList(),
onSelected: (value) => counterType = value!,
),
const SizedBox(height: 50),
TextField(
controller: nameController,
decoration: InputDecoration(
hintStyle: const TextStyle(color: Colors.blue),
hintText:
AppLocalizations.of(context)!.enter_counter_name),
),
const SizedBox(height: 50),
TextButton(
onPressed: () {
DBProvider.db
.updateCounter(Counter(
id: counter.id,
addressId: counter.addressId,
counterType: counterType,
name: nameController.text))
.then((value) => Navigator.pop(context));
},
child: Text(AppLocalizations.of(context)!.edit))
]),
),
),
);
}
}