import 'package:flutter/material.dart'; import 'package:manager_api_new/api.dart'; import 'package:manager_app/constants.dart'; class SingleChoiceInputContainer extends StatefulWidget { final String label; final String selectLabel; final T? selected; final List values; final ValueChanged onChanged; final double borderRadius; final Color selectedColor; final Color textColor; const SingleChoiceInputContainer({ Key? key, required this.label, required this.selectLabel, required this.selected, required this.values, required this.onChanged, this.borderRadius = 12, this.selectedColor = kPrimaryColor, this.textColor = kWhite, }) : super(key: key); @override State> createState() => _SingleChoiceInputContainerState(); } class _SingleChoiceInputContainerState extends State> { T? _selected; @override void initState() { super.initState(); _selected = widget.selected; } @override Widget build(BuildContext context) { return FormField( initialValue: _selected, builder: (state) { return Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Text( widget.label, style: const TextStyle( fontWeight: FontWeight.w400, fontSize: 16, ), ), const SizedBox(height: 8, width: 10), Container( width: 225, height: 60, padding: const EdgeInsets.symmetric(horizontal: 16), /*decoration: BoxDecoration( borderRadius: BorderRadius.circular(widget.borderRadius), border: Border.all(color: Colors.grey.shade400, width: 1.2), color: Colors.white, ),*/ child: DropdownButton( underline: const SizedBox( child: Divider(height: 0, thickness: 1.5, color: kPrimaryColor), ), focusColor: Colors.transparent, icon: const Icon(Icons.arrow_drop_down, color: kPrimaryColor), isExpanded: true, value: _selected, hint: Text( widget.selectLabel, style: TextStyle(color: Colors.grey.shade600), ), items: widget.values.map((v) { return DropdownMenuItem( value: v, child: Text( (v as SectionEventDTO).label ?? "", style: const TextStyle(fontSize: 14), ), ); }).toList(), onChanged: (value) { setState(() { if (value is SectionEventDTO && value.id == null) { _selected = null; // affiche le hint } else { _selected = value; } }); widget.onChanged(_selected); state.didChange(_selected); }, ), ), ], ); }, ); } }