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:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import '../providers/input_provider.dart'; import '../providers/input_provider.dart';
import '../providers/settings_provider.dart';
class DropDown extends StatelessWidget { class DropDown extends StatelessWidget {
const DropDown({super.key}); final List<String> _items;
const DropDown(this._items, {super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var inputModel = context.watch<InputProvider>(); var inputModel = context.watch<InputProvider>();
var settings = context.watch<SettingsProvider>();
return DropdownButtonFormField<String>( return DropdownButtonFormField<String>(
value: settings.settings?.relapseCategories?[0] ?? '', value: _items[0],
icon: const Icon(Icons.arrow_downward), icon: const Icon(Icons.arrow_downward),
elevation: 16, elevation: 16,
style: const TextStyle(color: Colors.deepPurple), style: const TextStyle(color: Colors.deepPurple),
onChanged: (String? value) { onChanged: (String? value) {
inputModel.relapseCategory = value ?? ''; inputModel.relapseCategory = value ?? '';
}, },
items: settings.settings?.relapseCategories items: _items.map<DropdownMenuItem<String>>((String value) {
?.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>( return DropdownMenuItem<String>(
value: value, value: value,
child: Text(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 'package:smoke_cess_app/widgets/text_formfield.dart';
import '../providers/input_provider.dart'; import '../providers/input_provider.dart';
import '../providers/settings_provider.dart';
import 'elevated_card.dart'; import 'elevated_card.dart';
class RelapseForm extends StatelessWidget { class RelapseForm extends StatelessWidget {
@ -12,12 +13,13 @@ class RelapseForm extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var inputModel = context.watch<InputProvider>(); var inputModel = context.watch<InputProvider>();
var settings = context.watch<SettingsProvider>();
return Column( return Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
const ElevatedCard( ElevatedCard(
title: 'Rückfallkategorie', title: 'Rückfallkategorie',
child: DropDown(), child: DropDown(settings.settings?.relapseCategories ?? []),
), ),
const ElevatedCard( const ElevatedCard(
title: 'Beschreibe deinen Rückfall', title: 'Beschreibe deinen Rückfall',