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/ErService/rapid-response-team/rrt-pickup-address-page.dart

309 lines
10 KiB
Dart

import 'dart:async';
import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/Addresses.dart';
import 'package:diplomaticquarterapp/core/viewModels/er/rrt-view-model.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/models/rrt/service_price.dart';
import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/location_page.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
3 years ago
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_material_pickers/flutter_material_pickers.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:google_maps_place_picker/google_maps_place_picker.dart';
import 'package:provider/provider.dart';
import 'package:diplomaticquarterapp/uitl/utils_new.dart';
import 'rrt-place-order.dart';
import 'package:diplomaticquarterapp/widgets/app_map/google_huawei_map.dart';
import 'package:diplomaticquarterapp/theme/colors.dart';
import 'package:diplomaticquarterapp/widgets/dialogs/select_location_dialog.dart';
import 'package:diplomaticquarterapp/core/service/AlHabibMedicalService/customer_addresses_service.dart';
3 years ago
class RRTRequestPickupAddressPage extends StatefulWidget {
final ServicePrice servicePrice;
3 years ago
RRTRequestPickupAddressPage({@required this.servicePrice});
@override
3 years ago
State<StatefulWidget> createState() => RRTRequestPickupAddressPageState();
}
3 years ago
class RRTRequestPickupAddressPageState extends State<RRTRequestPickupAddressPage> with SingleTickerProviderStateMixin {
bool acceptTerms = false;
bool mapIdle = true;
Completer<GoogleMapController> mapController = Completer();
static CameraPosition cameraPosition = CameraPosition(
target: LatLng(37.42796133580664, -122.085749655962),
zoom: 14.4746,
);
LatLng currentPostion;
List<AddressInfo> myAddresses = [];
AddressInfo selectedAddress;
StreamController<int> addressStreamController = StreamController();
Stream<int> addressStream;
StreamController<int> addressLoadingStreamController = StreamController();
Stream<int> addressLoadingStream;
3 years ago
// AddressInfo _selectedAddress;
double latitude = 0;
double longitude = 0;
AppMap appMap;
bool showCurrentLocation = false;
@override
3 years ago
void initState() {
goToCurrentLocation();
3 years ago
super.initState();
// addressStream = addressStreamController.stream;
// addressLoadingStream = addressLoadingStreamController.stream;
}
setLatitudeAndLongitude({bool isSetState = false, String latLong}) async {
if (latLong == null) {
if (myAddresses.isEmpty) {
setState(() {
showCurrentLocation = true;
});
} else {
latLong = myAddresses[myAddresses.length - 1].latLong;
}
}
if (!showCurrentLocation) {
List latLongArr = latLong.split(',');
latitude = double.parse(latLongArr[0]);
longitude = double.parse(latLongArr[1]);
print("sssss1 " + latitude.toString());
print("sssss2 " + longitude.toString());
currentPostion = LatLng(latitude, longitude);
setMap();
}
}
setMap() {
setState(() {
cameraPosition = CameraPosition(
target: currentPostion,
zoom: 14.4746,
);
appMap.moveTo(cameraPostion: cameraPosition);
});
}
3 years ago
void loadAddresses() async {
// GifLoaderDialogUtils.showMyDialog(context);
await viewModel.getCustomerInfo();
// GifLoaderDialogUtils.hideDialog(context);
if (viewModel.addressesList.isNotEmpty) setState(() {});
}
TranslationBase localize;
RRTViewModel viewModel;
3 years ago
@override
Widget build(BuildContext context) {
localize = TranslationBase.of(context);
ProjectViewModel projectViewModel = Provider.of(context);
addressStreamController.sink.add(0);
return BaseView<RRTViewModel>(
3 years ago
onModelReady: (vm) {
viewModel = vm;
loadAddresses();
myAddresses = viewModel.addressesList;
},
builder: (ctx, vm, widget) => AppScaffold(
appBarTitle: localize.pickupLocation,
isShowAppBar: true,
3 years ago
showNewAppBar: true,
showNewAppBarTitle: true,
baseViewModel: viewModel,
body: Column(
children: [
Card(
margin: EdgeInsets.only(left: 12, right: 12, bottom: 12, top: 12),
shape: cardRadius(12),
elevation: 3,
child: Container(
child: InkWell(
onTap: () => confirmSelectLocationDialog(myAddresses),
child: Container(
padding: EdgeInsets.all(8),
width: double.infinity,
// height: 65,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
getAddressName(),
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 12,
letterSpacing: -0.45,
),
),
),
Icon(Icons.arrow_drop_down)
],
),
),
),
height: 50,
width: double.infinity,
),
),
InkWell(
onTap: () async {
Navigator.push(
context,
FadePage(
page: LocationPage(
latitude: latitude,
longitude: longitude,
),
),
);
},
child: Padding(
padding: EdgeInsets.only(left: 12, right: 12, bottom: 16, top: 8),
child: Row(
children: [
Icon(Icons.add_circle_outline_sharp),
mWidth(12),
Text(
TranslationBase.of(context).addNewAddress,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
letterSpacing: -0.46,
),
),
],
),
),
),
Expanded(
child: Stack(
alignment: Alignment.center,
children: [
appMap = AppMap(cameraPosition.toMap(), onCameraMove: (camera) {
_updatePosition(camera);
}),
Icon(
Icons.place,
color: CustomColors.accentColor,
size: 50,
),
],
),
),
Padding(
padding: const EdgeInsets.only(left: 20, right: 20, top: 14, bottom: 14),
child: continueButton(),
),
],
3 years ago
)));
}
void _updatePosition(CameraPosition _position) {
latitude = _position.target.latitude;
longitude = _position.target.longitude;
}
3 years ago
Widget centerTargetPoint() {
double size = mapIdle ? 20 : 30;
double margin = mapIdle ? 3 : 10;
return Center(
child: Container(
3 years ago
width: size,
height: size,
decoration: BoxDecoration(borderRadius: BorderRadius.circular(20), border: Border.all(width: 2, color: Theme.of(context).appBarTheme.color)),
child: Container(margin: EdgeInsets.all(margin), decoration: BoxDecoration(color: Theme.of(context).appBarTheme.color, borderRadius: BorderRadius.circular(20))),
),
);
}
3 years ago
Widget continueButton() {
return Padding(
padding: const EdgeInsets.all(15),
3 years ago
child: DefaultButton(TranslationBase.of(context).continues, () {
Navigator.push(
context,
FadePage(
page: RRTPlaceOrderPage(
selectedAddress: selectedAddress,
servicePrice: widget.servicePrice,
)));
}),
);
}
void confirmSelectLocationDialog(List<AddressInfo> addresses) {
showDialog(
context: context,
child: SelectLocationDialog(
addresses: addresses,
3 years ago
selectedAddress: selectedAddress,
onValueSelected: (value) {
showCurrentLocation = false;
setLatitudeAndLongitude(latLong: value.latLong);
setState(() {
3 years ago
selectedAddress = value;
});
},
),
);
}
String getAddressName() {
3 years ago
if (selectedAddress != null && selectedAddress.address1 != null)
return selectedAddress.address1;
else
return TranslationBase.of(context).selectAddress;
}
3 years ago
moveToLocation(LatLng location, {bool animate = true}) async {
await Future.delayed(Duration(milliseconds: 200));
cameraPosition = CameraPosition(
3 years ago
target: location,
zoom: 16.4746,
);
if (animate)
(await mapController.future).animateCamera(
CameraUpdate.newCameraPosition(cameraPosition),
3 years ago
);
else
3 years ago
(await mapController.future).moveCamera(
CameraUpdate.newCameraPosition(cameraPosition),
3 years ago
);
}
3 years ago
goToCurrentLocation() async {
3 years ago
Geolocator.getCurrentPosition().then((value) {
selectedAddress = AddressInfo(latLong: '${value.latitude},${value.longitude}');
moveToLocation(LatLng(value.latitude, value.longitude));
});
}
// moveToLocation(LatLng(location.latitude, location.longitude), animate: false);
// }
3 years ago
}