Skip to content

Instantly share code, notes, and snippets.

@Roy-Tuhin
Last active September 8, 2021 12:57
Show Gist options
  • Save Roy-Tuhin/29256a888fd016940faf07ae470d1534 to your computer and use it in GitHub Desktop.
Save Roy-Tuhin/29256a888fd016940faf07ae470d1534 to your computer and use it in GitHub Desktop.
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
_getLabList();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Dynamic DropDownList REST API'),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
alignment: Alignment.topCenter,
margin: EdgeInsets.only(bottom: 100, top: 100),
child: Text(
'Depended Dropdown',
style: TextStyle(fontWeight: FontWeight.w800, fontSize: 20),
),
),
//======================================================== All Lab List
Container(
padding: EdgeInsets.only(left: 15, right: 15, top: 5),
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Expanded(
child: DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: DropdownButton<String>(
value: _myLab,
iconSize: 30,
icon: (null),
style: TextStyle(
color: Colors.black54,
fontSize: 16,
),
hint: Text('Select State'),
onChanged: (String newValue) {
setState(() {
_myLab = newValue;
_myTest = null;
_getTestList();
print(_myLab);
});
},
items: allLabList?.map((item) {
return new DropdownMenuItem(
child: new Text(item['PartnerName']),
value: item['EncPartnerId'].toString(),//=====id/encid here
);
})?.toList() ??
[],
),
),
),
),
],
),
),
SizedBox(
height: 30,
),
//======================================================== Test List depends on Lab
Container(
padding: EdgeInsets.only(left: 15, right: 15, top: 5),
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Expanded(
child: DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: DropdownButton<String>(
value: _myTest,//===============
iconSize: 30,
icon: (null),
style: TextStyle(
color: Colors.black54,
fontSize: 16,
),
hint: Text('Select City'),
onChanged: (String newValue) {
setState(() {
_myTest = newValue;
print(_myTest);
});
},
items: testList?.map((item) {
return new DropdownMenuItem(
child: new Text(item['TestName']),
value: item['TestId'].toString(),//============
);
})?.toList() ??
[],
),
),
),
),
],
),
),
],
),
);
}
//=============================================================================== Api Calling here
//CALLING LAB API HERE
// Get LAB information by API
List allLabList;
String _myLab;
String allLabInfoUrl = 'http://medbo.digitalicon.in/api/medboapi/AllPathLab';
Future<String> _getLabList() async {
await http.post(allLabInfoUrl, body: {
}).then((response) {
var data = json.decode(response.body);
// print(data);
setState(() {
allLabList = data['Partner'];
});
});
}
// Get TEST information by API
List testList;
String _myTest;
String allTestInfoUrl ='http://medbo.digitalicon.in/api/medboapi/GetTestByLab';
Future<String> _getTestList() async {
await http.post(allTestInfoUrl, body: {
"TestId": _myLab,
}).then((response) {
var data = json.decode(response.body);
setState(() {
testList = data['Data'];
});
});
}
}
// My Json Response for all Lab
{
"Status": "1",
"Message": "",
"Partner": [
{
"EncPartnerId": "IujyQXg8KZg8asLvK/FS7g==",
"PartnerName": "dasfdsf"
},
{
"EncPartnerId": "pEl2B9kuumKRxIxLJO76eQ==",
"PartnerName": "partner172"
},
{
"EncPartnerId": "eYwtNBXR6P/JDtsIwr+Bvw==",
"PartnerName": "nnkb"
},
{
"EncPartnerId": "kFgorcFF0G6RQD4W+LwWnQ==",
"PartnerName": "nnkjj"
},
{
"EncPartnerId": "U4exk+vfMGrn7cjNUa/PBw==",
"PartnerName": "mahadev"
},
{
"EncPartnerId": "tqkaSjTFgDf0612mp9mbsQ==",
"PartnerName": null
},
{
"EncPartnerId": "0aruO0FbYOu5IerRBxdT8w==",
"PartnerName": "Suraksha Diagnostics"
},
{
"EncPartnerId": "65gtodyhbtdInTsJWr1ZkA==",
"PartnerName": "Rasomoy pvt. Hospital"
},
{
"EncPartnerId": "LEuT1eIlpLEMAAkZme3wpQ==",
"PartnerName": "Tangra medical House"
},
{
"EncPartnerId": "q8O8YMzYKXSB4RtkX4k7Lw==",
"PartnerName": "Partner new"
}
]
}
//And depending upon Lab my Test response
{
"Status": "1",
"Message": "",
"Data": [
{
"TestId": "I3uXyzcuDZf21SSe5fHnSQ==",
"EncTestId": null,
"TestName": "RT-PCR",
"NoOfPartner": null,
"TestFee": null,
"DiscountedFee": null,
"BookingFee": null,
"ReportTime": null,
"Note": null,
"CreateBy": null,
"CreateDate": null,
"ModBy": null,
"ModDate": null,
"ActiveStatus": null,
"Permission": null
},
{
"TestId": "I3uXyzcuDZf21SSe5fHnSQ==",
"EncTestId": null,
"TestName": "RT-PCR",
"NoOfPartner": null,
"TestFee": null,
"DiscountedFee": null,
"BookingFee": null,
"ReportTime": null,
"Note": null,
"CreateBy": null,
"CreateDate": null,
"ModBy": null,
"ModDate": null,
"ActiveStatus": null,
"Permission": null
},
{
"TestId": "I3uXyzcuDZf21SSe5fHnSQ==",
"EncTestId": null,
"TestName": "RT-PCR",
"NoOfPartner": null,
"TestFee": null,
"DiscountedFee": null,
"BookingFee": null,
"ReportTime": null,
"Note": null,
"CreateBy": null,
"CreateDate": null,
"ModBy": null,
"ModDate": null,
"ActiveStatus": null,
"Permission": null
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment