You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diplomatic-quarter/lib/pages/MyAppointments/widgets/custom_radio.dart

115 lines
3.4 KiB
Dart

4 years ago
import 'package:diplomaticquarterapp/pages/MyAppointments/models/AskDocRequestTypeModel.dart';
import 'package:diplomaticquarterapp/pages/MyAppointments/widgets/askDocDialog.dart';
import 'package:diplomaticquarterapp/pages/MyAppointments/widgets/reminder_dialog.dart';
import 'package:flutter/material.dart';
class CustomRadio extends StatefulWidget {
4 years ago
List<AskDocRequestType> requestData;
CustomRadio({this.requestData});
@override
createState() {
return new CustomRadioState();
}
}
class CustomRadioState extends State<CustomRadio> {
List<RadioModel> sampleData = new List<RadioModel>();
@override
void initState() {
super.initState();
4 years ago
if (widget.requestData != null) {
widget.requestData.forEach((element) {
sampleData.add(
new RadioModel(false, element.description, element.parameterCode));
});
} else {
sampleData.add(new RadioModel(false, "Before 30 Mins", 30));
sampleData.add(new RadioModel(false, 'Before 1 Hour', 60));
sampleData.add(new RadioModel(false, 'Before 2 Hours', 120));
sampleData.add(new RadioModel(false, 'Before 4 Hours', 240));
}
}
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
ListView.builder(
shrinkWrap: true,
itemCount: sampleData.length,
itemBuilder: (BuildContext context, int index) {
return new InkWell(
//highlightColor: Colors.red,
splashColor: Colors.transparent,
onTap: () {
setState(() {
sampleData.forEach((element) => element.isSelected = false);
sampleData[index].isSelected = true;
4 years ago
if (widget.requestData != null) {
AskDocDialog.selectedParameterCode =
sampleData[index].duration;
print(AskDocDialog.selectedParameterCode);
} else {
ReminderDialog.selectedDuration =
sampleData[index].duration * 60000;
}
});
},
child: new RadioItem(sampleData[index]),
);
},
),
],
);
}
}
class RadioItem extends StatelessWidget {
final RadioModel _item;
RadioItem(this._item);
@override
Widget build(BuildContext context) {
return new Container(
margin: new EdgeInsets.all(15.0),
child: new Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
new Container(
height: 30.0,
width: 30.0,
child: new Center(
child: Image.asset("assets/images/new-design/check_icon.png",
width: 15.0, height: 15.0),
),
decoration: new BoxDecoration(
color: _item.isSelected ? Colors.blue : Colors.transparent,
border: new Border.all(
width: 1.0,
color: _item.isSelected ? Colors.blue : Colors.grey),
borderRadius: const BorderRadius.all(const Radius.circular(50.0)),
),
),
new Container(
margin: new EdgeInsets.only(left: 15.0),
child: new Text(_item.text, style: TextStyle(fontSize: 16.0)),
),
],
),
);
}
}
class RadioModel {
bool isSelected;
final String text;
final int duration;
RadioModel(this.isSelected, this.text, this.duration);
}