BUG FIXES

merge-requests/404/head
Sultan Khan 3 years ago
parent 062ca5c11c
commit 5b988dff4f

@ -66,7 +66,9 @@ class _NewHomeHealthCareStepOnePageState extends State<NewHomeHealthCareStepOneP
setState(() { setState(() {
if (!isServiceSelected(service.serviceID)) if (!isServiceSelected(service.serviceID))
widget.patientERInsertPresOrderRequestModel.patientERHHCInsertServicesList.add(PatientERHHCInsertServicesList( widget.patientERInsertPresOrderRequestModel.patientERHHCInsertServicesList.add(PatientERHHCInsertServicesList(
recordID: widget.patientERInsertPresOrderRequestModel.patientERHHCInsertServicesList.length, serviceID: service.serviceID, serviceName: service.description)); recordID: widget.patientERInsertPresOrderRequestModel.patientERHHCInsertServicesList.length,
serviceID: service.serviceID,
serviceName: projectViewModel.isArabic ? service.descriptionN : service.description));
else else
removeSelected(service.serviceID); removeSelected(service.serviceID);
// widget.patientERInsertPresOrderRequestModel // widget.patientERInsertPresOrderRequestModel

@ -6,47 +6,40 @@ import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class RRTLogPage extends StatefulWidget {
class RRTLogPage extends StatefulWidget{ final List<PrescriptionsOrder> orders;
final List<PrescriptionsOrder> orders;
const RRTLogPage({this.orders}); const RRTLogPage({this.orders});
@override @override
State<StatefulWidget> createState() => RRTLogPageState(); State<StatefulWidget> createState() => RRTLogPageState();
} }
class RRTLogPageState extends State<RRTLogPage>{
class RRTLogPageState extends State<RRTLogPage> {
RRTViewModel viewModel; RRTViewModel viewModel;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BaseView<RRTViewModel>( return BaseView<RRTViewModel>(
onModelReady: (vm) => viewModel = vm, onModelReady: (vm) => viewModel = vm,
builder: (ctx, vm, widgetState){ builder: (ctx, vm, widgetState) {
return ListView.builder( return ListView.builder(
itemCount: widget.orders.length, itemCount: widget.orders.length,
itemBuilder: (ctx, idx) { padding: EdgeInsets.all(21),
var order = widget.orders[idx]; itemBuilder: (ctx, idx) {
return RRTLogListItem(order, onCancel: deleteOrder); var order = widget.orders[idx];
} return RRTLogListItem(order, onCancel: deleteOrder);
); });
} });
);
} }
deleteOrder(PrescriptionsOrder order) async { deleteOrder(PrescriptionsOrder order) async {
GifLoaderDialogUtils.showMyDialog(context); GifLoaderDialogUtils.showMyDialog(context);
var success = await viewModel.cancelOrder(order); var success = await viewModel.cancelOrder(order);
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
if(success) if (success)
setState(() { setState(() {
widget.orders.remove(order); widget.orders.remove(order);
}); });
} }
} }

@ -4,6 +4,7 @@ import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
final _item_content_seperator = Container(height: 0.25, padding: EdgeInsets.all(10), color: Colors.grey.withOpacity(0.5)); final _item_content_seperator = Container(height: 0.25, padding: EdgeInsets.all(10), color: Colors.grey.withOpacity(0.5));
@ -22,59 +23,188 @@ class RRTLogListItem extends StatelessWidget {
ProjectViewModel projectViewModel = Provider.of(context); ProjectViewModel projectViewModel = Provider.of(context);
_context = context; _context = context;
localize = TranslationBase.of(context); localize = TranslationBase.of(context);
int status = order.status;
String _statusDisp = projectViewModel.isArabic ? order.descriptionN : order.description;
Color _color;
if (status == 1) {
//pending
_color = Color(0xffCC9B14);
} else if (status == 2) {
//processing
_color = Color(0xff2E303A);
} else if (status == 3) {
//completed
_color = Color(0xff359846);
} else if (status == 4) {
//cancel // Rejected
_color = Color(0xffD02127);
}
return Container( return Container(
padding: EdgeInsets.all(15), margin: EdgeInsets.all(5),
margin: EdgeInsets.symmetric(horizontal: 15, vertical: 10), decoration: BoxDecoration(
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(15), boxShadow: [BoxShadow(color: Colors.grey.withOpacity(0.25), spreadRadius: 1, blurRadius: 3)]), color: _color,
child: Column( borderRadius: BorderRadius.all(
crossAxisAlignment: CrossAxisAlignment.stretch, Radius.circular(10.0),
children: [ ),
_contentItem(label: localize.reqId, value: order.iD.toString()), boxShadow: [
_item_content_seperator, BoxShadow(
_contentItem(label: localize.status, value: projectViewModel.isArabic ? order.descriptionN.toString() : order.description.toString()), //order.getStatusName(localize)), color: Color(0xff000000).withOpacity(.05),
_item_content_seperator, blurRadius: 27,
_contentItem(label: localize.pickupDate, value: order.getFormattedDateTime()), offset: Offset(0, -3),
_item_content_seperator, ),
_contentItem(label: localize.location, value: order.getNearestProjectDescription()),
_item_content_seperator,
SizedBox(height: 10),
if (onCancel != null && order.status == 1 && order.status == 2) FractionallySizedBox(child: cancelButton())
], ],
), ),
); child: Container(
} // decoration: containerColorRadiusLeft(Colors.white, 12),
margin: EdgeInsets.only(left: projectViewModel.isArabic ? 0 : 6, right: projectViewModel.isArabic ? 6 : 0),
Widget _contentItem({@required String label, String value}) { padding: EdgeInsets.symmetric(vertical: 14, horizontal: 12),
return Container( decoration: BoxDecoration(
padding: EdgeInsets.symmetric(vertical: 10), color: Colors.white,
child: Column( border: Border.all(color: Colors.white, width: 1),
crossAxisAlignment: CrossAxisAlignment.start, borderRadius: BorderRadius.only(
children: [ bottomRight: projectViewModel.isArabic ? Radius.circular(0) : Radius.circular(10.0),
Text( topRight: projectViewModel.isArabic ? Radius.circular(0) : Radius.circular(10.0),
label, bottomLeft: projectViewModel.isArabic ? Radius.circular(10.0) : Radius.circular(0),
style: TextStyle(color: Theme.of(_context).appBarTheme.color, fontSize: 9, letterSpacing: 1), topLeft: projectViewModel.isArabic ? Radius.circular(10.0) : Radius.circular(0),
),
SizedBox(
height: 5,
), ),
Text( ),
value, // clipBehavior: Clip.antiAlias,
style: TextStyle(color: Theme.of(_context).appBarTheme.color, fontWeight: FontWeight.bold, fontSize: 14), child: Row(
), crossAxisAlignment: CrossAxisAlignment.start,
], children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_statusDisp,
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: _color, letterSpacing: -0.4, height: 16 / 10),
),
SizedBox(height: 6),
Text(
'${TranslationBase.of(context).requestID}: ${order.iD}',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xff2E303A), letterSpacing: -0.64, height: 25 / 16),
),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
TranslationBase.of(context).location + ": ",
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xff575757), letterSpacing: -0.4, height: 16 / 10),
),
Expanded(
child: Text(
!projectViewModel.isArabic ? order.nearestProjectDescription.trim().toString() : order.nearestProjectDescriptionN.toString(),
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.56),
),
),
],
),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
localize.pickupDate + ": ",
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xff575757), letterSpacing: -0.4, height: 16 / 10),
),
Expanded(
child: Text(
order.getFormattedDateTime(),
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.56),
),
),
],
),
],
),
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
DateUtil.formatDateToDate(order.createdOn, projectViewModel.isArabic),
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.4, height: 16 / 10),
),
SizedBox(height: 12),
if (order.status == 1 || order.status == 2)
InkWell(
onTap: () {
onCancel(order);
},
child: Container(
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 14),
decoration: BoxDecoration(
color: Color(0xffD02127),
border: Border.all(color: Colors.white, width: 1),
borderRadius: BorderRadius.circular(10),
),
child: Text(
TranslationBase.of(context).cancel_nocaps,
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Colors.white, letterSpacing: -0.4),
),
),
),
],
),
],
),
), ),
); );
// return Container(
// padding: EdgeInsets.all(15),
// margin: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
// decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(15), boxShadow: [BoxShadow(color: Colors.grey.withOpacity(0.25), spreadRadius: 1, blurRadius: 3)]),
// child: Column(
// crossAxisAlignment: CrossAxisAlignment.stretch,
// children: [
// _contentItem(label: localize.reqId, value: order.iD.toString()),
// _item_content_seperator,
// _contentItem(label: localize.status, value: projectViewModel.isArabic ? order.descriptionN.toString() : order.description.toString()), //order.getStatusName(localize)),
// _item_content_seperator,
// _contentItem(label: localize.pickupDate, value: order.getFormattedDateTime()),
// _item_content_seperator,
// _contentItem(label: localize.location, value: order.getNearestProjectDescription()),
// _item_content_seperator,
// SizedBox(height: 10),
// if (order.status == 1 || order.status == 2) Container(child: cancelButton())
// ],
// ),
// );
} }
Widget cancelButton() => MaterialButton( // Widget _contentItem({@required String label, String value}) {
height: 45, // return Container(
color: Color(0xFFc5272d), // padding: EdgeInsets.symmetric(vertical: 10),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)), // child: Column(
onPressed: () => onCancel(order), // crossAxisAlignment: CrossAxisAlignment.start,
child: Text( // children: [
localize.cancel, // Text(
style: TextStyle(color: Colors.white, fontSize: 13), // label,
), // style: TextStyle(color: Theme.of(_context).appBarTheme.color, fontSize: 9, letterSpacing: 1),
); // ),
// SizedBox(
// height: 5,
// ),
// Text(
// value,
// style: TextStyle(color: Theme.of(_context).appBarTheme.color, fontWeight: FontWeight.bold, fontSize: 14),
// ),
// ],
// ),
// );
// }
// Widget cancelButton() => MaterialButton(
// height: 45,
// color: Color(0xFFc5272d),
// shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
// onPressed: () => onCancel(order),
// child: Text(
// localize.cancel,
// style: TextStyle(color: Colors.white, fontSize: 13),
// ),
// );
} }

@ -53,21 +53,21 @@ class RRTRequestPickupAddressPageState extends State<RRTRequestPickupAddressPage
Stream<int> addressStream; Stream<int> addressStream;
StreamController<int> addressLoadingStreamController = StreamController(); StreamController<int> addressLoadingStreamController = StreamController();
Stream<int> addressLoadingStream; Stream<int> addressLoadingStream;
AddressInfo _selectedAddress; // AddressInfo _selectedAddress;
double latitude = 0; double latitude = 0;
double longitude = 0; double longitude = 0;
AppMap appMap; AppMap appMap;
bool showCurrentLocation = false; bool showCurrentLocation = false;
@override @override
void initState() { void initState() {
super.initState();
goToCurrentLocation(); goToCurrentLocation();
super.initState();
// addressStream = addressStreamController.stream; // addressStream = addressStreamController.stream;
// addressLoadingStream = addressLoadingStreamController.stream; // addressLoadingStream = addressLoadingStreamController.stream;
} }
setLatitudeAndLongitude({bool isSetState = false, String latLong}) async { setLatitudeAndLongitude({bool isSetState = false, String latLong}) async {
print("latLong " + latLong.toString());
if (latLong == null) { if (latLong == null) {
if (myAddresses.isEmpty) { if (myAddresses.isEmpty) {
setState(() { setState(() {
@ -86,7 +86,6 @@ class RRTRequestPickupAddressPageState extends State<RRTRequestPickupAddressPage
print("sssss1 " + latitude.toString()); print("sssss1 " + latitude.toString());
print("sssss2 " + longitude.toString()); print("sssss2 " + longitude.toString());
currentPostion = LatLng(latitude, longitude); currentPostion = LatLng(latitude, longitude);
selectedAddress = AddressInfo(latLong: '${latitude},${longitude}', address1: "", address2: "");
setMap(); setMap();
} }
} }
@ -220,67 +219,12 @@ class RRTRequestPickupAddressPageState extends State<RRTRequestPickupAddressPage
child: continueButton(), child: continueButton(),
), ),
], ],
) )));
// Column(
// crossAxisAlignment: CrossAxisAlignment.stretch,
// children: [
// StreamBuilder<Object>(
// stream: addressStream,
// builder: (context, snapshot) {
// return selectAddressField();
// }),
// StreamBuilder<Object>(
// stream: addressLoadingStream,
// builder: (context, snapshot) {
// return snapshot.hasData
// ? LinearProgressIndicator(backgroundColor: Colors.transparent)
// : Container(
// height: 4,
// );
// }),
// Expanded(
// child: PlacePicker(
// apiKey: GOOGLE_API_KEY,
// enableMyLocationButton: true,
// automaticallyImplyAppBarLeading: false,
// autocompleteOnTrailingWhitespace: true,
// selectInitialPosition: true,
// autocompleteLanguage: projectViewModel.currentLanguage,
// enableMapTypeButton: true,
// searchForInitialValue: false,
// selectedPlaceWidgetBuilder: (_, selectedPlace, state, isSearchBarFocused) {
// if (state == SearchingState.Idle) {
// addressLoadingStreamController.sink.add(null);
// if (selectedPlace != null) {
// var loc = selectedPlace.geometry.location;
// var address1 = selectedPlace.addressComponents.first.longName;
// var address2 = "";
// if (selectedPlace.addressComponents.length > 1) address2 = selectedPlace.addressComponents[1].longName;
// selectedAddress = Addresses(latLong: '${loc.lat},${loc.lng}', address1: address1, address2: address2);
// addressStreamController.sink.add(0);
// }
// } else {
// addressLoadingStreamController.sink.add(0);
// }
// return Container();
// },
// initialPosition: LatLng(24.7114693, 46.67469582),
// useCurrentLocation: false,
// ),
// ),
// continueButton()
// ],
// )
));
} }
void _updatePosition(CameraPosition _position) { void _updatePosition(CameraPosition _position) {
latitude = _position.target.latitude; latitude = _position.target.latitude;
longitude = _position.target.longitude; longitude = _position.target.longitude;
selectedAddress = AddressInfo(latLong: '${latitude},${longitude}', address1: "", address2: "");
} }
Widget centerTargetPoint() { Widget centerTargetPoint() {
@ -296,30 +240,6 @@ class RRTRequestPickupAddressPageState extends State<RRTRequestPickupAddressPage
); );
} }
// Widget selectAddressField() {
// var text = selectedAddress == null ? localize.selectAddress : selectedAddress.toString();
// return Container(
// margin: EdgeInsets.all(10),
// height: 50,
// child: MaterialButton(
// height: 50,
// color: Colors.white,
// shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
// onPressed: openAddressSelectDialog,
// child: Row(
// children: [
// Expanded(child: Text(text, style: TextStyle(color: Colors.grey, fontSize: 13, letterSpacing: 1))),
// Icon(
// Icons.keyboard_arrow_down,
// size: 20,
// color: Colors.grey,
// )
// ],
// ),
// ),
// );
// }
Widget continueButton() { Widget continueButton() {
return Padding( return Padding(
padding: const EdgeInsets.all(15), padding: const EdgeInsets.all(15),
@ -335,52 +255,18 @@ class RRTRequestPickupAddressPageState extends State<RRTRequestPickupAddressPage
); );
} }
// openAddressSelectDialog() {
// showMaterialResponsiveDialog(
// hideButtons: true,
// context: context,
// title: localize.selectAddress,
// child: ListView.separated(
// shrinkWrap: true,
// padding: EdgeInsets.all(10),
// itemCount: myAddresses.length,
// itemBuilder: (ctx, idx) {
// var itm = myAddresses[idx];
// return ListTile(
// title: Text(itm.toString()),
// onTap: () {
// setState(() {
// selectedAddress = itm;
// Navigator.pop(context);
// if (itm.latLong != null && itm.latLong.isNotEmpty && itm.latLong.split(',').length > 1) {
// var cordinates = itm.latLong.split(',');
// var latlng = LatLng(double.parse(cordinates.first), double.parse(cordinates.last));
// //moveToLocation(latlng);
// } else {
// AppToast.showErrorToast(message: 'Invalid address coordinates');
// }
// });
// },
// );
// },
// separatorBuilder: (ctx, idx) => Container(
// height: 0.25,
// color: Colors.grey.withOpacity(0.7),
// )));
// }
void confirmSelectLocationDialog(List<AddressInfo> addresses) { void confirmSelectLocationDialog(List<AddressInfo> addresses) {
showDialog( showDialog(
context: context, context: context,
child: SelectLocationDialog( child: SelectLocationDialog(
addresses: addresses, addresses: addresses,
selectedAddress: _selectedAddress, selectedAddress: selectedAddress,
onValueSelected: (value) { onValueSelected: (value) {
showCurrentLocation = false; showCurrentLocation = false;
setLatitudeAndLongitude(latLong: value.latLong); setLatitudeAndLongitude(latLong: value.latLong);
setState(() { setState(() {
_selectedAddress = value; selectedAddress = value;
}); });
}, },
), ),
@ -388,8 +274,8 @@ class RRTRequestPickupAddressPageState extends State<RRTRequestPickupAddressPage
} }
String getAddressName() { String getAddressName() {
if (_selectedAddress != null) if (selectedAddress != null && selectedAddress.address1 != null)
return _selectedAddress.address1; return selectedAddress.address1;
else else
return TranslationBase.of(context).selectAddress; return TranslationBase.of(context).selectAddress;
} }
@ -411,13 +297,10 @@ class RRTRequestPickupAddressPageState extends State<RRTRequestPickupAddressPage
} }
goToCurrentLocation() async { goToCurrentLocation() async {
var location = await Geolocator.getLastKnownPosition(); Geolocator.getCurrentPosition().then((value) {
if (location == null) { selectedAddress = AddressInfo(latLong: '${value.latitude},${value.longitude}');
Geolocator.getCurrentPosition().then((value) { moveToLocation(LatLng(value.latitude, value.longitude));
moveToLocation(LatLng(value.latitude, value.longitude)); });
});
return;
}
} }
// moveToLocation(LatLng(location.latitude, location.longitude), animate: false); // moveToLocation(LatLng(location.latitude, location.longitude), animate: false);

@ -123,25 +123,27 @@ class RRTPlaceOrderPage extends StatelessWidget {
Widget selectedAddressField() { Widget selectedAddressField() {
var address = "${selectedAddress.address1 ?? ''} ${selectedAddress.address2 ?? ''}"; var address = "${selectedAddress.address1 ?? ''} ${selectedAddress.address2 ?? ''}";
return Container( return selectedAddress.address1 != null
margin: EdgeInsets.symmetric(vertical: 10), ? Container(
child: MaterialButton( margin: EdgeInsets.symmetric(vertical: 10),
height: 50, child: MaterialButton(
color: Colors.white, height: 50,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)), color: Colors.white,
onPressed: () {}, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
child: Row( onPressed: () {},
children: [ child: Row(
Expanded(child: Text(address, style: TextStyle(color: Colors.black87, fontSize: 15, letterSpacing: 1))), children: [
Icon( Expanded(child: Text(address, style: TextStyle(color: Colors.black87, fontSize: 12, letterSpacing: 1))),
Icons.location_on_rounded, Icon(
size: 30, Icons.location_on_rounded,
color: Colors.black, size: 30,
) color: Colors.black,
], )
), ],
), ),
); ),
)
: SizedBox();
} }
Widget submitButton(BuildContext context) { Widget submitButton(BuildContext context) {

@ -76,6 +76,7 @@ class RRTRequestPageState extends State<RRTRequestPage> {
var orders = widget.pendingOrders; var orders = widget.pendingOrders;
return ListView.builder( return ListView.builder(
itemCount: orders.length, itemCount: orders.length,
padding: EdgeInsets.all(21),
itemBuilder: (ctx, idx) { itemBuilder: (ctx, idx) {
var order = orders[idx]; var order = orders[idx];
return RRTLogListItem(order, onCancel: deleteOrder); return RRTLogListItem(order, onCancel: deleteOrder);

@ -19,6 +19,7 @@ import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.dart'; import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
class SchedulePage extends StatefulWidget { class SchedulePage extends StatefulWidget {
DoctorList doctorList; DoctorList doctorList;
@ -61,11 +62,14 @@ class _SchedulePageState extends State<SchedulePage> {
onModelReady: (model2) => model2.getFreeSlots(doctorList), onModelReady: (model2) => model2.getFreeSlots(doctorList),
allowAny: true, allowAny: true,
builder: (_, model2, widget2) { builder: (_, model2, widget2) {
if (model.freeSlots.length > 0 && isPageChange == false) { if (model.freeSlots.length > 0 && isPageChange == false && model.state == ViewState.Idle) {
this.freeSlots = model.freeSlots; this.freeSlots = model.freeSlots;
this.doctorScheduleResponse = model.getDoctorScheduleList; this.doctorScheduleResponse = model.getDoctorScheduleList;
this.generateWeeksSchedules(); this.generateWeeksSchedules();
} else if (model.freeSlots.length == 0 && model.state == ViewState.Idle) {
AppToast.showErrorToast(message: TranslationBase.of(context).emptySchedule);
Navigator.pop(context);
} }
return AppScaffold( return AppScaffold(
appBarTitle: TranslationBase.of(context).schedule, appBarTitle: TranslationBase.of(context).schedule,

@ -1,4 +1,3 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
@ -7,8 +6,7 @@ import 'package:flutter_hms_gms_availability/flutter_hms_gms_availability.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:huawei_map/map.dart' as hmsMap; import 'package:huawei_map/map.dart' as hmsMap;
class AppMap extends StatefulWidget {
class AppMap extends StatefulWidget{
CameraPositionCallback onCameraMove; CameraPositionCallback onCameraMove;
Map initialCamera; Map initialCamera;
@ -17,22 +15,20 @@ class AppMap extends StatefulWidget{
AppMap(this.initialCamera, {this.onCameraMove}); AppMap(this.initialCamera, {this.onCameraMove});
@override @override
State<StatefulWidget> createState() => _state = AppMapState(); State<StatefulWidget> createState() => _state = AppMapState();
moveTo({@required CameraPosition cameraPostion}) {
moveTo({@required CameraPosition cameraPostion}){ if (_state.isHuawei) {
if(_state.isHuawei){
final cameraJson = cameraPostion.toMap(); final cameraJson = cameraPostion.toMap();
final camera = hmsMap.CameraPosition.fromMap(cameraJson); final camera = hmsMap.CameraPosition.fromMap(cameraJson);
_state._huaweiMapController.animateCamera(hmsMap.CameraUpdate.newCameraPosition(camera)); _state._huaweiMapController.animateCamera(hmsMap.CameraUpdate.newCameraPosition(camera));
}else{ } else {
_state.googleMapController.animateCamera(CameraUpdate.newCameraPosition(cameraPostion)); _state.googleMapController.animateCamera(CameraUpdate.newCameraPosition(cameraPostion));
} }
} }
} }
class AppMapState extends State<AppMap>{ class AppMapState extends State<AppMap> {
bool isHuawei; bool isHuawei;
Completer<GoogleMapController> _googleMapControllerComp = Completer(); Completer<GoogleMapController> _googleMapControllerComp = Completer();
@ -41,10 +37,11 @@ class AppMapState extends State<AppMap>{
Completer<hmsMap.HuaweiMapController> _huaweiMapControllerComp = Completer(); Completer<hmsMap.HuaweiMapController> _huaweiMapControllerComp = Completer();
hmsMap.HuaweiMapController _huaweiMapController; hmsMap.HuaweiMapController _huaweiMapController;
checkIsHuawei() async{ checkIsHuawei() async {
isHuawei = await FlutterHmsGmsAvailability.isHmsAvailable; isHuawei = await FlutterHmsGmsAvailability.isHmsAvailable;
setState(() {}); setState(() {});
} }
@override @override
void initState() { void initState() {
checkIsHuawei(); checkIsHuawei();
@ -52,43 +49,39 @@ class AppMapState extends State<AppMap>{
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if(isHuawei == null) if (isHuawei == null) return CircularProgressIndicator();
return CircularProgressIndicator();
return map(); return map();
} }
Widget map() => isHuawei ? huaweiMap() : googleMap(); Widget map() => isHuawei ? huaweiMap() : googleMap();
googleMap() {
googleMap(){ return GoogleMap(
return mapType: MapType.normal,
GoogleMap( zoomControlsEnabled: false,
mapType: MapType.normal, myLocationButtonEnabled: true,
zoomControlsEnabled: false, myLocationEnabled: true,
myLocationButtonEnabled: true, initialCameraPosition: CameraPosition.fromMap(widget.initialCamera),
myLocationEnabled: true, onCameraMove: widget.onCameraMove,
initialCameraPosition: CameraPosition.fromMap(widget.initialCamera), onMapCreated: (GoogleMapController controller) {
onCameraMove: widget.onCameraMove, googleMapController = controller;
onMapCreated: (GoogleMapController controller) { _googleMapControllerComp.complete(controller);
googleMapController = controller; },
_googleMapControllerComp.complete(controller); );
},
);
} }
Widget huaweiMap(){ Widget huaweiMap() {
return hmsMap.HuaweiMap( return hmsMap.HuaweiMap(
mapType: hmsMap.MapType.normal, mapType: hmsMap.MapType.normal,
zoomControlsEnabled: false, zoomControlsEnabled: false,
myLocationButtonEnabled: true, myLocationButtonEnabled: true,
myLocationEnabled: true, myLocationEnabled: true,
initialCameraPosition: hmsMap.CameraPosition.fromMap(widget.initialCamera), initialCameraPosition: hmsMap.CameraPosition.fromMap(widget.initialCamera),
onCameraMove: (camera) => widget.onCameraMove(CameraPosition.fromMap(camera.toMap())), onCameraMove: (camera) => widget.onCameraMove(CameraPosition.fromMap(camera.toMap())),
onMapCreated: (controller){ onMapCreated: (controller) {
_huaweiMapController = controller; _huaweiMapController = controller;
_huaweiMapControllerComp .complete(controller); _huaweiMapControllerComp.complete(controller);
}, },
); );
} }
} }
Loading…
Cancel
Save