From cbf384f9e9851aa5e7907136aae9fc22a1aa7c17 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Mon, 27 Feb 2023 02:35:17 +0100 Subject: [PATCH] Refactoring: DropDown more modular --- lib/widgets/drop_down.dart | 10 ++++------ lib/widgets/relapse_form.dart | 6 ++++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/widgets/drop_down.dart b/lib/widgets/drop_down.dart index 2df8b07..ae4dec9 100644 --- a/lib/widgets/drop_down.dart +++ b/lib/widgets/drop_down.dart @@ -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 _items; + const DropDown(this._items, {super.key}); @override Widget build(BuildContext context) { var inputModel = context.watch(); - var settings = context.watch(); return DropdownButtonFormField( - 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>((String value) { + items: _items.map>((String value) { return DropdownMenuItem( value: value, child: Text(value), diff --git a/lib/widgets/relapse_form.dart b/lib/widgets/relapse_form.dart index b80fcba..cc53a53 100644 --- a/lib/widgets/relapse_form.dart +++ b/lib/widgets/relapse_form.dart @@ -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(); + var settings = context.watch(); 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',