Refactoring: DropDown more modular

main
Kai Mannweiler 2023-02-27 02:35:17 +01:00
parent 63fdda8195
commit cbf384f9e9
2 changed files with 8 additions and 8 deletions

View File

@ -1,25 +1,23 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/input_provider.dart';
import '../providers/settings_provider.dart';
class DropDown extends StatelessWidget {
const DropDown({super.key});
final List<String> _items;
const DropDown(this._items, {super.key});
@override
Widget build(BuildContext context) {
var inputModel = context.watch<InputProvider>();
var settings = context.watch<SettingsProvider>();
return DropdownButtonFormField<String>(
value: settings.settings?.relapseCategories?[0] ?? '',
value: _items[0],
icon: const Icon(Icons.arrow_downward),
elevation: 16,
style: const TextStyle(color: Colors.deepPurple),
onChanged: (String? value) {
inputModel.relapseCategory = value ?? '';
},
items: settings.settings?.relapseCategories
?.map<DropdownMenuItem<String>>((String value) {
items: _items.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),

View File

@ -4,6 +4,7 @@ import 'package:smoke_cess_app/widgets/drop_down.dart';
import 'package:smoke_cess_app/widgets/text_formfield.dart';
import '../providers/input_provider.dart';
import '../providers/settings_provider.dart';
import 'elevated_card.dart';
class RelapseForm extends StatelessWidget {
@ -12,12 +13,13 @@ class RelapseForm extends StatelessWidget {
@override
Widget build(BuildContext context) {
var inputModel = context.watch<InputProvider>();
var settings = context.watch<SettingsProvider>();
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const ElevatedCard(
ElevatedCard(
title: 'Rückfallkategorie',
child: DropDown(),
child: DropDown(settings.settings?.relapseCategories ?? []),
),
const ElevatedCard(
title: 'Beschreibe deinen Rückfall',