Last active
September 9, 2021 10:11
-
-
Save Roy-Tuhin/9dfbbc2d48eed6116e92851f26564277 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
import 'package:date_time_picker/date_time_picker.dart'; | |
import 'package:flutter/material.dart'; | |
import 'AllPathLabTestModel.dart'; | |
import 'package:http/http.dart' as http; | |
import 'Dependent_DropDown_in_MultipleTest_Model.dart'; | |
class MultipleTestBooking extends StatefulWidget { | |
const MultipleTestBooking({Key? key}) : super(key: key); | |
@override | |
_MultipleTestBookingState createState() => _MultipleTestBookingState(); | |
} | |
class _MultipleTestBookingState extends State<MultipleTestBooking> { | |
String encLabId = ''; | |
void initState(){ | |
super.initState(); | |
AllPathLab(); | |
} | |
String _selectedDate = DateTime.now().toString(); | |
final List<String> allLabList = [ | |
"Select Lab", | |
"Abc", | |
"Xyz", | |
]; | |
String selectedLabFromList = "Abc"; | |
@override | |
Widget build(BuildContext context) { | |
var screenWidth = MediaQuery.of(context).size.width; | |
var screenHeight = MediaQuery.of(context).size.height; | |
var blockSizeHorizontal = (screenWidth / 100); | |
var blockSizeVertical = (screenHeight / 100); | |
return Scaffold( | |
body: SafeArea( | |
child: Container( | |
child: Column( | |
children: [ | |
Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: ListTile( | |
title: Text("Booking Information", | |
style: TextStyle( | |
fontWeight: FontWeight.bold, | |
fontSize: blockSizeHorizontal * 5, | |
fontFamily: 'Poppins', | |
color: Theme.of(context).primaryColor, | |
)), | |
subtitle: Text("Preferred Visit Date"), | |
), | |
), | |
//============================================================================== | |
Container( | |
margin: EdgeInsets.only(left: 20), | |
padding: EdgeInsets.only(left: 0, right: 150), | |
decoration: BoxDecoration( | |
color: Colors.lightBlue[50], | |
borderRadius: BorderRadius.all(Radius.circular(12)), | |
), | |
child: Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: DateTimePicker( | |
initialValue: DateTime.now().toString(), | |
//initialValue:'', // initialValue or controller.text can be null, empty or a DateTime string otherwise it will throw an error. | |
type: DateTimePickerType.date, | |
dateLabelText: 'Select Date', | |
style: TextStyle( | |
fontWeight: FontWeight.bold, | |
fontSize: blockSizeHorizontal * 3.5, | |
fontFamily: 'Poppins', | |
color: Colors.green, | |
letterSpacing: 2.0, | |
), | |
firstDate: DateTime.now(), | |
lastDate: DateTime.now().add(Duration( | |
days: 30)), // This will add one year from current date | |
validator: (value) { | |
return null; | |
}, | |
onChanged: (value) { | |
if (value.isNotEmpty) { | |
setState(() { | |
_selectedDate = value; | |
}); | |
} | |
}, | |
onSaved: (value) { | |
if (value.isNotEmpty) { | |
_selectedDate = value; | |
} | |
}, | |
), | |
), | |
), | |
//============================================================================== | |
ListTile( | |
title: Text( | |
"Select Pathological Lab", | |
style: TextStyle( | |
fontWeight: FontWeight.bold, | |
fontSize: blockSizeHorizontal * 4.0, | |
fontFamily: 'Poppins', | |
color: Theme.of(context).primaryColor, | |
), | |
), | |
), | |
Container( | |
child: FutureBuilder<List<Partner>>( | |
future: AllPathLab(), | |
builder: | |
(BuildContext context, AsyncSnapshot snapshot) { | |
if (snapshot.connectionState !=ConnectionState.done) { | |
return CircularProgressIndicator(); | |
} | |
if (snapshot.hasError) { | |
return Text("Somthing went wrong"); | |
} | |
if (snapshot.hasData) { | |
return DropdownButton<Partner>( | |
value: _val, | |
hint: Text("Select Lab"), | |
//underline: SizedBox(), | |
//isExpanded: true, | |
items: snapshot.data.map((Partner data) => | |
DropdownMenuItem<Partner>( | |
child: Text("${data.partnerName}"), | |
value: data, | |
) | |
).toList().cast<DropdownMenuItem<Partner>>(), | |
onChanged: (value){ | |
setState(() { | |
_val=value; | |
encLabId = value!.encPartnerId; | |
GetTestByLab(); | |
}); | |
}); | |
} | |
return Text("Waiting for Internet Connection"); | |
}, | |
), | |
), | |
//=========================================================== Dependent drop down=================================== | |
ListTile( | |
title: Text( | |
"Test Name", | |
style: TextStyle( | |
fontWeight: FontWeight.bold, | |
fontSize: blockSizeHorizontal * 4.0, | |
fontFamily: 'Poppins', | |
color: Theme.of(context).primaryColor, | |
), | |
), | |
), | |
Container( | |
child: FutureBuilder<List<Datum>>( | |
future: GetTestByLab(), | |
builder: | |
(BuildContext context, AsyncSnapshot snapshot) { | |
if (snapshot.connectionState !=ConnectionState.done) { | |
return CircularProgressIndicator(); | |
} | |
if (snapshot.hasError) { | |
return Text("Somthing went wrong"); | |
} | |
if (snapshot.hasData) { | |
return DropdownButton<Datum>( | |
hint: Text(""), | |
//underline: SizedBox(), | |
//isExpanded: true, | |
items: snapshot.data.map((Datum data) => | |
DropdownMenuItem<Datum>( | |
child: Text("${data.testName}"), | |
value: data, | |
) | |
).toList().cast<DropdownMenuItem<Datum>>(), | |
onChanged: (value){ | |
//GetTestByLab(value!.encPartnerId); // passing encid to my next API function | |
}); | |
} | |
return Text("Waiting for Internet Connection"); | |
}, | |
), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
//========================================================================================================================================================================== | |
Future<List<Partner>> AllPathLab() async { | |
var jsonResponse; | |
var response = await http.post(Uri.parse("http://medbo.digitalicon.in/api/medboapi/AllPathLab"), | |
body: ({ | |
})); | |
if (response.statusCode == 200) { | |
print("Correct"); | |
// print(response.body); | |
jsonResponse = json.decode(response.body.toString()); | |
print(jsonResponse); | |
AllPathLabTestModel dataModel = allPathLabTestModelFromJson(response.body); | |
print(dataModel.partner.length); | |
for (final item in dataModel.partner) { | |
print(item.partnerName); | |
} | |
List<Partner> arrData = dataModel.partner; // this "partner" is actual json array of data[] | |
return arrData; | |
} else { | |
print("Wrong URL"); | |
throw Exception("Faild to fetch"); | |
} | |
} | |
//========================================================================================================================================================================== | |
Future<List<Datum>> GetTestByLab() async { | |
var jsonResponse; | |
var response = await http.post(Uri.parse("http://medbo.digitalicon.in/api/medboapi/GetTestByLab"), | |
body: ({ | |
"EncId": encLabId | |
//"EncId": 'I3uXyzcuDZf21SSe5fHnSQ==' | |
})); | |
if (response.statusCode == 200) { | |
print("Correct"); | |
// print(response.body); | |
jsonResponse = json.decode(response.body.toString()); | |
print(jsonResponse); | |
DependentDropDownModel dataModel = dependentDropDownModelFromJson(response.body); | |
print(dataModel.data.length); | |
for (final item in dataModel.data) | |
print(item.testName); | |
// print(item.testId); | |
List<Datum> arrData = dataModel.data; // this "partner" is actual json array of data[] | |
return arrData; | |
} else { | |
print("Wrong URL"); | |
throw Exception("Faild to fetch"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment