import 'package:hmg_patient_app/uitl/translations_delegate_base.dart'; import 'package:hmg_patient_app/widgets/buttons/defaultButton.dart'; import 'package:flutter/material.dart'; class RadioSelectionDialogModel { String title; int value; RadioSelectionDialogModel(this.title, this.value); } class RadioSelectionDialog extends StatefulWidget { final Function(int)? onValueSelected; final List? listData; final int? selectedIndex; final bool? isScrollable; final bool? isShowSearch; final String? buttonText; const RadioSelectionDialog({Key? key, this.onValueSelected, this.listData, this.selectedIndex, this.isScrollable = false, this.isShowSearch = false, this.buttonText = ""}) : super(key: key); @override State createState() => new RadioSelectionDialogState(); } class RadioSelectionDialogState extends State { late int selectedIndex; List tempListData = []; TextEditingController controller = new TextEditingController(); @override void initState() { selectedIndex = widget.selectedIndex ?? 0; super.initState(); addAllData(); } addAllData() { tempListData.clear(); for (int i = 0; i < widget.listData!.length; i++) { tempListData.add(widget.listData![i]); } setState(() {}); } Widget build(BuildContext context) { return Dialog( backgroundColor: Colors.white, shape: RoundedRectangleBorder(), insetPadding: EdgeInsets.only(left: 21, right: 21), child: Padding( padding: EdgeInsets.only(left: 20, right: 20, top: 18, bottom: 28), child: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( child: Padding( padding: const EdgeInsets.only(top: 16.0), child: Text( TranslationBase.of(context).select, style: TextStyle(fontSize: 24, fontWeight: FontWeight.w600, color: Color(0xff2B353E), height: 35 / 24, letterSpacing: -0.96), ), ), ), IconButton( padding: EdgeInsets.zero, icon: Icon(Icons.close), color: Color(0xff2B353E), constraints: BoxConstraints(), onPressed: () { Navigator.pop(context); }, ) ], ), SizedBox(height: 21), Text( TranslationBase.of(context).pleaseSelectFromBelowOptions, style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.56), ), widget.isShowSearch! ? Padding( padding: const EdgeInsets.all(8.0), child: TextField( controller: controller, onChanged: (v) { if (v.length > 0) { tempListData.clear(); for (int i = 0; i < widget.listData!.length; i++) { if (widget.listData![i].title.toLowerCase().contains(v.toLowerCase())) { tempListData.add(widget.listData![i]); } } } else { addAllData(); } setState(() {}); }, decoration: InputDecoration( hintStyle: TextStyle(fontSize: 17), hintText: 'Search Insurance', suffixIcon: Icon(Icons.search), border: InputBorder.none, contentPadding: EdgeInsets.all(12), ), ), ) : Container(), SizedBox(height: widget.isScrollable! ? 12 : 0), SizedBox( height: widget.isScrollable! ? MediaQuery.of(context).size.height * .4 : null, child: ListView.separated( physics: widget.isScrollable! ? BouncingScrollPhysics() : NeverScrollableScrollPhysics(), // shrinkWrap: !widget.isScrollable, shrinkWrap: !widget.isScrollable!, padding: EdgeInsets.only(bottom: widget.isScrollable! ? 21 : 42, top: 10), itemBuilder: (context, index) { return InkWell( onTap: () { setState(() { selectedIndex = tempListData[index].value; }); }, child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox( width: 22, height: 22, child: Radio( value: tempListData[index].value, groupValue: selectedIndex, onChanged: (value) { setState(() { selectedIndex = value!; }); }, ), ), SizedBox(width: 8), Expanded( child: Text( tempListData[index].title, // maxLines: 2, style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xff575757), letterSpacing: -0.56), ), ), ], ), ); }, separatorBuilder: (context, index) => SizedBox(height: 10), itemCount: tempListData.length), ), SizedBox(height: widget.isScrollable! ? 12 : 0), Row( mainAxisSize: MainAxisSize.min, children: [ Expanded( child: DefaultButton( widget.buttonText!.isNotEmpty ? widget.buttonText! : TranslationBase.of(context).save, () { Navigator.pop(context); widget.onValueSelected!(selectedIndex); }, color: Color(0xff349745), ), ), ], ), ], ), ), ), ); } }