Refactoring: DropDown more modular
parent
63fdda8195
commit
cbf384f9e9
|
@ -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),
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue