Files
fcs/lib/pages/widgets/local_radio_buttons.dart

92 lines
2.8 KiB
Dart
Raw Normal View History

2020-10-14 01:51:53 +06:30
import 'package:fcs/helpers/theme.dart';
import 'package:flutter/material.dart';
class LocalRadioButtons<T> extends StatelessWidget {
2021-09-10 14:25:37 +06:30
final Function(T)? callback;
final IconData? iconData;
final T? selectedValue;
final List<T>? values;
2020-10-18 02:38:46 +06:30
final bool readOnly;
final bool hideUnselected;
2020-10-14 01:51:53 +06:30
const LocalRadioButtons(
2021-09-10 14:25:37 +06:30
{Key? key,
2020-10-18 02:38:46 +06:30
this.callback,
this.iconData,
this.selectedValue,
this.values,
this.readOnly = false,
this.hideUnselected = true})
2020-10-14 01:51:53 +06:30
: super(key: key);
@override
Widget build(BuildContext context) {
2020-10-18 02:38:46 +06:30
return Column(children: readOnly ? getReadonlyChildren() : getChildren());
2020-10-14 01:51:53 +06:30
}
List<Widget> getChildren() {
2021-09-10 14:25:37 +06:30
return values!
2020-10-14 01:51:53 +06:30
.toList()
.map((e) => SizedBox(
height: 30,
child: InkWell(
2021-09-10 14:25:37 +06:30
onTap: () => callback!(e),
2020-10-14 01:51:53 +06:30
child: Row(children: <Widget>[
Radio<T>(
2024-02-02 18:00:51 +06:30
fillColor: MaterialStateProperty.resolveWith((states) {
// active
if (states.contains(MaterialState.selected)) {
return primaryColor;
}
// inactive
return labelColor;
}),
2020-10-14 01:51:53 +06:30
activeColor: primaryColor,
groupValue: selectedValue,
value: e,
2021-09-10 14:25:37 +06:30
onChanged: (T? value) {
callback!(value!);
2020-10-14 01:51:53 +06:30
},
),
2024-02-01 18:07:40 +06:30
Text(e.toString(),
style: TextStyle(
2024-02-02 18:00:51 +06:30
fontSize: 15,
2024-02-01 18:07:40 +06:30
color:
e == selectedValue ? primaryColor : Colors.black)),
2020-10-14 01:51:53 +06:30
]),
)))
.toList();
}
2020-10-18 02:38:46 +06:30
List<Widget> getReadonlyChildren() {
2021-09-10 14:25:37 +06:30
return values!
2020-10-18 02:38:46 +06:30
.toList()
.map((e) => hideUnselected && e == selectedValue
? SizedBox(
height: 30,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(
e == selectedValue ? Icons.check : Icons.remove,
color:
e == selectedValue ? primaryColor : Colors.grey,
),
),
2024-02-02 18:00:51 +06:30
Text(
e.toString(),
style: TextStyle(
fontSize: 15,
color: e == selectedValue
? primaryColor
: Colors.black),
),
2020-10-18 02:38:46 +06:30
]),
)
: Container())
.toList();
}
2020-10-14 01:51:53 +06:30
}