89 lines
2.6 KiB
Dart
89 lines
2.6 KiB
Dart
import 'package:auto_size_text/auto_size_text.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:manager_app/constants.dart';
|
|
|
|
class SingleSelectContainer extends StatefulWidget {
|
|
final Color? color;
|
|
final String label;
|
|
final String? initialValue;
|
|
final List<String> inputValues;
|
|
final ValueChanged<String>? onChanged;
|
|
final double fontSize;
|
|
final double fontSizeText;
|
|
const SingleSelectContainer({
|
|
Key? key,
|
|
this.color = kSecond,
|
|
required this.label,
|
|
this.initialValue = "",
|
|
required this.inputValues,
|
|
this.onChanged,
|
|
this.fontSize = 25,
|
|
this.fontSizeText = 20,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
_SingleSelectContainerState createState() => _SingleSelectContainerState();
|
|
}
|
|
|
|
class _SingleSelectContainerState extends State<SingleSelectContainer> {
|
|
String? selectedValue;
|
|
|
|
@override
|
|
void initState() {
|
|
selectedValue = widget.initialValue;
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Size size = MediaQuery.of(context).size;
|
|
|
|
return Container(
|
|
child: Row(
|
|
children: [
|
|
Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: AutoSizeText(
|
|
widget.label,
|
|
style: TextStyle(fontSize: widget.fontSize, fontWeight: FontWeight.w300),
|
|
maxLines: 2,
|
|
maxFontSize: widget.fontSize,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Container(
|
|
width: size.width *0.15,
|
|
constraints: BoxConstraints(maxWidth: 175),
|
|
child: DropdownButton<String>(
|
|
value: selectedValue,
|
|
icon: const Icon(Icons.arrow_downward),
|
|
iconSize: 24,
|
|
elevation: 16,
|
|
style: TextStyle(color: widget.color!),
|
|
underline: Container(
|
|
height: 2,
|
|
color: kPrimaryColor,
|
|
),
|
|
onChanged: (String? newValue) {
|
|
setState(() {
|
|
selectedValue = newValue!;
|
|
widget.onChanged!(selectedValue!);
|
|
});
|
|
},
|
|
items: widget.inputValues.map<DropdownMenuItem<String>>((String value) {
|
|
return DropdownMenuItem<String>(
|
|
value: value,
|
|
child: Text(value, style: TextStyle(fontSize: 20, fontWeight: FontWeight.w400, color: widget.color)),
|
|
);
|
|
}).toList(),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
} |