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

73 lines
2.0 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>(
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
},
),
Text(e.toString()),
]),
)))
.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,
),
),
Text(e.toString()),
]),
)
: Container())
.toList();
}
2020-10-14 01:51:53 +06:30
}