refactoring code

merge-requests/44/head
unknown 6 years ago
parent ae524100f7
commit 734b7b2c99

@ -1,3 +1,4 @@
/*
*@author: Ibrahim Albitar
*@Date:27/4/2020
@ -5,42 +6,62 @@
*@return:
*@desc:
*/
class PharmaciesListRequestModel {
// {"ItemID":90417,
// "LanguageID":2,
// "stamp":"2020-03-08T07:49:14.067Z",
// "IPAdress":"11.11.11.11",
// "VersionID":1.2,
// "Channel":9,
// "TokenID":"PpIU/OWJ40yxMHQtCXL0DA==",
// "SessionID":"dz1hqVj1Fk",
// "IsLoginForDoctorApp":true,
// "PatientOutSA":false,
// "PatientTypeID":1}
int ItemID;
int LanguageID;
int itemID;
int languageID;
String stamp;
String IPAdress;
double VersionID;
String TokenID;
String SessionID;
bool IsLoginForDoctorApp;
bool PatientOutSA;
int PatientTypeID;
int Channel;
String ipAdress;
double versionID;
String tokenID;
String sessionID;
bool isLoginForDoctorApp;
bool patientOutSA;
int patientTypeID;
int channel;
PharmaciesListRequestModel(
{this.ItemID,
this.PatientTypeID,
this.LanguageID,
this.stamp,
this.IPAdress,
this.VersionID,
this.TokenID,
this.SessionID,
this.IsLoginForDoctorApp,
this.Channel,
this.PatientOutSA});
}
{this.itemID ,
this.patientTypeID = 1,
this.languageID = 2,
this.stamp = '2020-04-23T21:01:21.492Z',
this.ipAdress = '11.11.11.11',
this.versionID = 1.2,
this.tokenID = '@dm!n',
this.sessionID = 'e29zoooEJ4',
this.isLoginForDoctorApp = true,
this.channel = 9,
this.patientOutSA = false});
PharmaciesListRequestModel.fromJson(Map<String, dynamic> json) {
itemID = json['ItemID'];
patientTypeID = json['PatientTypeID'];
languageID = json['LanguageID'];
stamp = json['stamp'];
ipAdress = json['IPAdress'];
versionID = json['VersionID'];
tokenID = json['TokenID'];
sessionID = json['SessionID'];
isLoginForDoctorApp = json['IsLoginForDoctorApp'];
channel = json['Channel'];
patientOutSA = json['PatientOutSA'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['ItemID'] = this.itemID;
data['PatientTypeID'] = this.patientTypeID;
data['LanguageID'] = this.languageID;
data['stamp'] = this.stamp;
data['IPAdress'] = this.ipAdress;
data['VersionID'] = this.versionID;
data['TokenID'] = this.tokenID;
data['SessionID'] = this.sessionID;
data['IsLoginForDoctorApp'] = this.isLoginForDoctorApp;
data['PatientOutSA'] = this.patientOutSA;
data['Channel'] = this.channel;
return data;
}
}

@ -6,26 +6,54 @@
*@desc:
*/
class PharmaciesItemsRequestModel {
String PHR_itemName;
int LanguageID;
String phrItemName;
int languageID;
String stamp;
String IPAdress;
double VersionID;
String TokenID;
String SessionID;
bool IsLoginForDoctorApp;
bool PatientOutSA;
int PatientTypeID;
String ipAdress;
double versionID;
String tokenID;
String sessionID;
bool isLoginForDoctorApp;
bool patientOutSA;
int patientTypeID;
PharmaciesItemsRequestModel(
{this.PHR_itemName,
this.PatientTypeID,
this.LanguageID,
this.stamp,
this.IPAdress,
this.VersionID,
this.TokenID,
this.SessionID,
this.IsLoginForDoctorApp,
this.PatientOutSA});
{this.phrItemName = '',
this.patientTypeID = 1,
this.languageID = 2,
this.stamp = '2020-04-23T21:01:21.492Z',
this.ipAdress = '11.11.11.11',
this.versionID = 1.2,
this.tokenID = '@dm!n',
this.sessionID = 'e29zoooEJ4',
this.isLoginForDoctorApp = true,
this.patientOutSA = false});
PharmaciesItemsRequestModel.fromJson(Map<String, dynamic> json) {
phrItemName = json['PHR_itemName'];
patientTypeID = json['PatientTypeID'];
languageID = json['LanguageID'];
stamp = json['stamp'];
ipAdress = json['IPAdress'];
versionID = json['VersionID'];
tokenID = json['TokenID'];
sessionID = json['SessionID'];
isLoginForDoctorApp = json['IsLoginForDoctorApp'];
patientOutSA = json['PatientOutSA'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['PHR_itemName'] = this.phrItemName;
data['PatientTypeID'] = this.patientTypeID;
data['LanguageID'] = this.languageID;
data['stamp'] = this.stamp;
data['IPAdress'] = this.ipAdress;
data['VersionID'] = this.versionID;
data['TokenID'] = this.tokenID;
data['SessionID'] = this.sessionID;
data['IsLoginForDoctorApp'] = this.isLoginForDoctorApp;
data['PatientOutSA'] = this.patientOutSA;
return data;
}
}

@ -4,51 +4,88 @@ import 'package:doctor_app_flutter/client/app_client.dart';
import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/models/pharmacies_List_request_model.dart';
import 'package:doctor_app_flutter/models/pharmacies_items_request_model.dart';
import 'package:doctor_app_flutter/util/helpers.dart';
import 'package:flutter/cupertino.dart';
class MedicineProvider with ChangeNotifier {
var pharmacyItemsList = [];
var pharmaciesList = [];
bool isFinished = false;
bool hasError = false;
String errorMsg = '';
Future<Map> getMedicineItem(PharmaciesItemsRequestModel medicine) async {
PharmaciesItemsRequestModel _itemsRequestModel =PharmaciesItemsRequestModel();
PharmaciesListRequestModel _listRequestModel = PharmaciesListRequestModel();
Future<String> getMedicineItem(String itemName) async {
try {
final response = await AppClient.post(PHARMACY_ITEMS_URL,
body: json.encode({
"PHR_itemName": medicine.PHR_itemName,
"LanguageID": medicine.LanguageID,
"stamp": medicine.stamp,
"IPAdress": medicine.IPAdress,
"VersionID": medicine.VersionID,
"TokenID": medicine.TokenID,
"SessionID": medicine.SessionID,
"IsLoginForDoctorApp": medicine.IsLoginForDoctorApp,
"PatientOutSA": medicine.PatientOutSA,
"PatientTypeID": medicine.PatientTypeID
}));
return Future.value(json.decode(response.body));
if (await Helpers.checkConnection()) {
_itemsRequestModel.phrItemName = itemName;
final response = await AppClient.post(PHARMACY_ITEMS_URL,
body: json.encode(_itemsRequestModel.toJson()));
final int statusCode = response.statusCode;
if (statusCode < 200 || statusCode >= 400 || json == null) {
isFinished = true;
hasError = true;
errorMsg = 'Error While Fetching data';
} else {
var parsed = json.decode(response.body.toString());
if (parsed['MessageStatus'] == 1) {
pharmacyItemsList = parsed['ListPharmcy'];
hasError = false;
isFinished = true;
errorMsg = "Done";
} else {
hasError = true;
errorMsg = parsed['ErrorMessage'] ?? parsed['ErrorEndUserMessage'];
}
}
} else {
isFinished = true;
hasError = true;
errorMsg = 'Please Check The Internet Connection';
}
notifyListeners();
} catch (error) {
throw error;
}
}
return errorMsg;
}
Future<Map> getPharmaciesList(PharmaciesListRequestModel pharmacy) async {
Future<String> getPharmaciesList(int itemId) async {
try {
final response = await AppClient.post(PHARMACY_LIST_URL,
body: json.encode({
"ItemID": pharmacy.ItemID,
"LanguageID": pharmacy.LanguageID,
"stamp": pharmacy.stamp,
"IPAdress": pharmacy.IPAdress,
"VersionID": pharmacy.VersionID,
"TokenID": pharmacy.TokenID,
"SessionID": pharmacy.SessionID,
"IsLoginForDoctorApp": pharmacy.IsLoginForDoctorApp,
"PatientOutSA": pharmacy.PatientOutSA,
"Channel": pharmacy.Channel,
"PatientTypeID": pharmacy.PatientTypeID
}));
return Future.value(json.decode(response.body));
if (await Helpers.checkConnection()) {
_listRequestModel.itemID = itemId;
final response = await AppClient.post(PHARMACY_LIST_URL,
body: json.encode(_listRequestModel.toJson()));
final int statusCode = response.statusCode;
if (statusCode < 200 || statusCode >= 400 || json == null) {
isFinished = true;
hasError = true;
errorMsg = 'Error While Fetching data';
} else {
var parsed = json.decode(response.body.toString());
if (parsed['MessageStatus'] == 1) {
pharmaciesList = parsed['PharmList'];
hasError = false;
isFinished = true;
errorMsg = "Done";
} else {
hasError = true;
errorMsg = parsed['ErrorMessage'] ?? parsed['ErrorEndUserMessage'];
}
}
} else {
isFinished = true;
hasError = true;
errorMsg = 'Please Check The Internet Connection';
}
notifyListeners();
} catch (error) {
throw error;
}
return errorMsg;
}
}

@ -1,5 +1,7 @@
import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/providers/doctor_reply_provider.dart';
import 'package:doctor_app_flutter/providers/medicine_provider.dart';
import 'package:doctor_app_flutter/screens/medicine/medicine_search_screen.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:provider/provider.dart';
import '../routes.dart';
@ -212,7 +214,6 @@ class _DashboardScreenState extends State<DashboardScreen> {
flex: 2,
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
@ -242,12 +243,25 @@ class _DashboardScreenState extends State<DashboardScreen> {
children: <Widget>[
Expanded(
flex: 2,
child: new DashboardItemIconText(
DoctorApp.home_icon,
"",
"In Patient",
showBorder: false,
backgroundColor: Colors.blueGrey[900],
child: InkWell(
child: DashboardItemIconText(
DoctorApp.home_icon,
"",
"In Patient",
showBorder: false,
backgroundColor: Colors.blueGrey[900],
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChangeNotifierProvider(
create: (_) => MedicineProvider(),
child: MedicineSearchScreen(),
),
),
);
},
),
),
Expanded(

@ -1,6 +1,5 @@
import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/models/pharmacies_items_request_model.dart';
import 'package:doctor_app_flutter/providers/medicine_provider.dart';
import 'package:doctor_app_flutter/screens/medicine/pharmacies_list_screen.dart';
import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart';
@ -13,7 +12,6 @@ import 'package:doctor_app_flutter/widgets/shared/app_text_form_field.dart';
import 'package:doctor_app_flutter/widgets/shared/rounded_container_widget.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../routes.dart';
import '../../util/extenstions.dart';
DrAppSharedPreferances sharedPref = DrAppSharedPreferances();
@ -31,101 +29,89 @@ class _MedicineSearchState extends State<MedicineSearchScreen> {
final myController = TextEditingController();
Helpers helpers = new Helpers();
var _medicineModel = PharmaciesItemsRequestModel(
IsLoginForDoctorApp: true,
PatientOutSA: false,
PatientTypeID: 1,
LanguageID: 2,
IPAdress: "11.11.11.11",
VersionID: 1.2,
TokenID: "2Fi7HoIHB0eDyekVa6tCJg==",
stamp: "2020-04-23T21:01:21.492Z",
SessionID: "e29zoooEJ4");
MedicineProvider _medicineProvider;
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => MedicineProvider(), //change builder to create
child: Consumer<MedicineProvider>(
builder: (context, provider, child) => AppScaffold(
appBarTitle: "Search Medicine",
body: Column(
children: <Widget>[
RoundedContainer(
child: Column(
children: <Widget>[
Icon(
Icons.search,
size: SizeConfig.imageSizeMultiplier * 15,
),
Padding(
padding: EdgeInsets.only(
bottom: SizeConfig.heightMultiplier * 5,
right: SizeConfig.heightMultiplier * 3,
left: SizeConfig.heightMultiplier * 3,
top: SizeConfig.heightMultiplier * 3),
child: AppTextFormField(
hintText: 'Type Medicine Name Here..',
controller: myController,
onSaved: (value) {},
// validator: (value) {
// return TextValidator().validateName(value);
// },
inputFormatter: ONLY_LETTERS),
)
],
)),
Container(
margin: EdgeInsets.all(SizeConfig.widthMultiplier * 5),
child: Wrap(
alignment: WrapAlignment.center,
children: <Widget>[
AppButton(
title: "Search",
color: Color(0xff58434F),
onPressed: () {
MedicineProvider medicineProvider =
Provider.of<MedicineProvider>(context);
searchMedicine(context, medicineProvider);
},
),
],
),
),
Expanded(
child: Container(
width: SizeConfig.screenWidth * 0.80,
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: data == null ? 0 : data.length,
itemBuilder: (BuildContext context, int index) {
return InkWell(
child: MedicineItemWidget(
label: data[index]["ItemDescription"],
),
onTap: () {
//Navigator.of(context).pushNamed(PHARMACIES_LIST);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PharmaciesListScreen(
itemID: data[index]["ItemID"]),
),
);
},
);
},
),
_medicineProvider = Provider.of(context);
return AppScaffold(
appBarTitle: "Search Medicine",
body: Column(
children: <Widget>[
RoundedContainer(
child: Column(
children: <Widget>[
Icon(
Icons.search,
size: SizeConfig.imageSizeMultiplier * 15,
),
Padding(
padding: EdgeInsets.only(
bottom: SizeConfig.heightMultiplier * 5,
right: SizeConfig.heightMultiplier * 3,
left: SizeConfig.heightMultiplier * 3,
top: SizeConfig.heightMultiplier * 3),
child: AppTextFormField(
hintText: 'Type Medicine Name Here..',
controller: myController,
onSaved: (value) {},
// validator: (value) {
// return TextValidator().validateName(value);
// },
inputFormatter: ONLY_LETTERS),
)
],
)),
Container(
margin: EdgeInsets.all(SizeConfig.widthMultiplier * 5),
child: Wrap(
alignment: WrapAlignment.center,
children: <Widget>[
AppButton(
title: "Search",
color: Color(0xff58434F),
onPressed: () {
searchMedicine(context);
},
),
],
),
),
Expanded(
child: Container(
width: SizeConfig.screenWidth * 0.80,
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: data == null ? 0 : data.length,
itemBuilder: (BuildContext context, int index) {
return InkWell(
child: MedicineItemWidget(
label: data[index]["ItemDescription"],
),
),
],
))));
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChangeNotifierProvider(
create: (_) => MedicineProvider(),
child: PharmaciesListScreen(
itemID: data[index]["ItemID"]),
),
),
);
},
);
},
),
),
),
],
));
}
searchMedicine(context, MedicineProvider medicineProvider) {
searchMedicine(context) {
FocusScope.of(context).unfocus();
if (myController.text.isNullOrEmpty()) {
this.setState(() {
data = null;
@ -133,29 +119,10 @@ class _MedicineSearchState extends State<MedicineSearchScreen> {
helpers.showErrorToast("Type Medicine Name");
return;
}
_medicineModel.PHR_itemName = myController.text;
medicineProvider.getMedicineItem(_medicineModel).then((res) {
if (res['MessageStatus'] == 1) {
print("ListMedicine " + res['ListPharmcy'].toString());
this.setState(() {
data = res['ListPharmcy'];
});
//Navigator.of(context).pushNamed(PHARMACIES_LIST);
} else {
// handel error
this.setState(() {
data = null;
});
widget.showCenterShortLoadingToast("watting");
helpers.showErrorToast(res['ErrorEndUserMessage']);
}
// Navigator.of(context).pushNamed(HOME);
}).catchError((err) {
print('$err');
_medicineProvider.getMedicineItem(myController.text).then((str) {
this.setState(() {
data = null;
data = _medicineProvider.pharmacyItemsList;
});
helpers.showErrorToast();
});
}
}

@ -6,6 +6,7 @@ import 'package:doctor_app_flutter/util/helpers.dart';
import 'package:doctor_app_flutter/widgets/medicine/medicine_item_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/dr_app_circular_progress_Indeicator.dart';
import 'package:doctor_app_flutter/widgets/shared/rounded_container_widget.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
@ -23,130 +24,105 @@ class PharmaciesListScreen extends StatefulWidget {
}
class _PharmaciesListState extends State<PharmaciesListScreen> {
var data;
var _data;
Helpers helpers = new Helpers();
var _pharmaciesModel = PharmaciesListRequestModel(
IsLoginForDoctorApp: true,
PatientOutSA: false,
PatientTypeID: 1,
LanguageID: 2,
IPAdress: "11.11.11.11",
VersionID: 1.2,
TokenID: "2Fi7HoIHB0eDyekVa6tCJg==",
stamp: "2020-04-23T21:01:21.492Z",
Channel: 9,
SessionID: "e29zoooEJ4");
MedicineProvider _medicineProvider;
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => MedicineProvider(),
//change builder to create
child: Consumer<MedicineProvider>(
builder: (context, provider, child) => AppScaffold(
appBarTitle: "Pharmacies List",
body: Column(
children: <Widget>[
RoundedContainer(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
AppText(
"Description",
margin: 10,
fontWeight: FontWeight.bold,
),
AppText(
"ItemDescription",
marginLeft: 10,
marginTop: 0,
marginRight: 10,
marginBottom: 10,
),
AppText(
"Price",
margin: 10,
fontWeight: FontWeight.bold,
),
AppText("SellingPrice",
marginLeft: 10,
marginTop: 0,
marginRight: 10,
marginBottom: 10,
),
],
)),
Container(
margin: EdgeInsets.all(SizeConfig.widthMultiplier * 5),
child: Align(
alignment: Alignment.centerLeft,
child: AppText(
"You can Find it in",
fontWeight: FontWeight.bold,
fontSize: SizeConfig.textMultiplier * 3,
))),
Expanded(
child: Container(
width: SizeConfig.screenWidth * 0.80,
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: data == null ? 0 : data.length,
itemBuilder: (BuildContext context, int index) {
return InkWell(
child: MedicineItemWidget(
label: data[index]["ItemDescription"],
_medicineProvider = Provider.of(context);
pharmaciesList();
return AppScaffold(
appBarTitle: "Pharmacies List",
body: Column(
children: <Widget>[
RoundedContainer(
child: !_medicineProvider.isFinished
? DrAppCircularProgressIndeicator()
: _medicineProvider.hasError
? Center(
child: Text(
_medicineProvider.errorMsg,
style: TextStyle(
color: Theme.of(context).errorColor),
),
)
: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
AppText(
"Description",
margin: 10,
fontWeight: FontWeight.bold,
),
AppText(
_data[0]["ItemDescription"],
marginLeft: 10,
marginTop: 0,
marginRight: 10,
marginBottom: 10,
),
AppText(
"Price",
margin: 10,
fontWeight: FontWeight.bold,
),
onTap: () {
//Navigator.of(context).pushNamed(PHARMACIES_LIST);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PharmaciesListScreen(
itemID: data[index]["ItemID"]),
),
);
},
);
},
),
AppText(
_data[0]["SellingPrice"].toString(),
marginLeft: 10,
marginTop: 0,
marginRight: 10,
marginBottom: 10,
),
],
)),
Container(
margin: EdgeInsets.all(SizeConfig.widthMultiplier * 5),
child: Align(
alignment: Alignment.centerLeft,
child: AppText(
"You can Find it in",
fontWeight: FontWeight.bold,
fontSize: SizeConfig.textMultiplier * 3,
))),
Expanded(
child: Container(
width: SizeConfig.screenWidth * 0.80,
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: _data == null ? 0 : _data.length,
itemBuilder: (BuildContext context, int index) {
return InkWell(
child: MedicineItemWidget(
label: _data[index]["LocationDescription"],
),
),
],
)
// RaisedButton(
// onPressed: () {
//
// },
// )
)));
onTap: () {
//Navigator.of(context).pushNamed(PHARMACIES_LIST);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PharmaciesListScreen(
itemID: _data[index]["ItemID"]),
),
);
},
);
},
),
),
),
],
));
}
pharmaciesList(context) {
_pharmaciesModel.ItemID = widget.itemID;
MedicineProvider medicineProvider =
Provider.of<MedicineProvider>(context);
medicineProvider.getPharmaciesList(_pharmaciesModel).then((res) {
print(res.toString());
if (res['MessageStatus'] == 1) {
print("ListPharmcy " + res['PharmList'].toString());
this.setState(() {
data = res['PharmList'];
});
//Navigator.of(context).pushNamed();
} else {
// handel error
// widget.showCenterShortLoadingToast("watting");
//helpers.showErrorToast(res['ErrorEndUserMessage']);
print(res['MessageStatus'].toString());
}
// Navigator.of(context).pushNamed(HOME);
}).catchError((err) {
print('$err');
//helpers.showErrorToast();
Future<bool> pharmaciesList() async {
_medicineProvider.getPharmaciesList(widget.itemID).then((result) {
this.setState(() {
_data = _medicineProvider.pharmaciesList;
});
});
return true;
}
}

Loading…
Cancel
Save