import 'package:amap_map_example/widgets/amap_gridview.dart'; import 'package:flutter/material.dart'; class AMapRadioGroup extends StatefulWidget { final String? groupLabel; final T? groupValue; final Map? radioValueMap; final ValueChanged? onChanged; AMapRadioGroup( {Key? key, this.groupLabel, this.groupValue, this.radioValueMap, this.onChanged}) : super(key: key); @override _AMapRadioGroupState createState() => _AMapRadioGroupState(); } class _AMapRadioGroupState extends State> { T? _groupValue; @override void initState() { super.initState(); _groupValue = (widget.groupValue); } @override Widget build(BuildContext context) { List radioList = []; _groupValue = (widget.groupValue); Widget _myRadio(String label, dynamic radioValue) { return Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Text(label), Radio( value: radioValue, groupValue: _groupValue, onChanged: (T? _value) { setState(() { _groupValue = _value; }); widget.onChanged!(_value); }, ), ], ); } if (widget.radioValueMap != null) { widget.radioValueMap!.forEach((key, value) { radioList.add(_myRadio(key, value)); }); } return Container( padding: EdgeInsets.all(5), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Text(widget.groupLabel!), Container( padding: EdgeInsets.only(left: 10), child: AMapGradView( childrenWidgets: radioList, ), ), ], ), ); } }