98 lines
3.1 KiB
Dart
98 lines
3.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:manager_app/constants.dart';
|
|
|
|
class SegmentedEnumInputContainer<T> extends StatefulWidget {
|
|
final String label;
|
|
final T selected;
|
|
final List<T> values;
|
|
final Map<T, Map<String, dynamic>> inputValues; // {'label': String, 'icon': IconData}
|
|
final ValueChanged<T> onChanged;
|
|
final double borderRadius;
|
|
final Color selectedColor;
|
|
final Color unselectedColor;
|
|
final Color textColor;
|
|
|
|
const SegmentedEnumInputContainer({
|
|
Key? key,
|
|
required this.label,
|
|
required this.selected,
|
|
required this.values,
|
|
required this.inputValues,
|
|
required this.onChanged,
|
|
this.borderRadius = 12,
|
|
this.selectedColor = kPrimaryColor,
|
|
this.unselectedColor = kSecond,
|
|
this.textColor = Colors.white,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
_SegmentedEnumInputContainerState<T> createState() =>
|
|
_SegmentedEnumInputContainerState<T>();
|
|
}
|
|
|
|
class _SegmentedEnumInputContainerState<T>
|
|
extends State<SegmentedEnumInputContainer<T>> {
|
|
late T selectedValue;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
selectedValue = widget.selected;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FormField<T>(
|
|
initialValue: selectedValue,
|
|
builder: (state) {
|
|
return InputDecorator(
|
|
decoration: InputDecoration(
|
|
labelText: widget.label,
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(widget.borderRadius)),
|
|
contentPadding: EdgeInsets.symmetric(horizontal: 25, vertical: 20),
|
|
),
|
|
child: Row(
|
|
children: widget.values.map((v) {
|
|
bool isSelected = v == selectedValue;
|
|
final data = widget.inputValues[v]!;
|
|
return Expanded(
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
setState(() {
|
|
selectedValue = v;
|
|
state.didChange(v);
|
|
});
|
|
widget.onChanged(v);
|
|
},
|
|
child: AnimatedContainer(
|
|
duration: Duration(milliseconds: 250),
|
|
margin: EdgeInsets.symmetric(horizontal: 4),
|
|
padding: EdgeInsets.symmetric(vertical: 10),
|
|
decoration: BoxDecoration(
|
|
color: isSelected ? widget.selectedColor : kSecond,
|
|
borderRadius: BorderRadius.circular(widget.borderRadius),
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(data['icon'], color: widget.textColor),
|
|
SizedBox(width: 4),
|
|
Text(
|
|
data['label'],
|
|
style: TextStyle(
|
|
color: widget.textColor, fontWeight: FontWeight.w400),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}).toList(),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|