Untitled
unknown
plain_text
2 years ago
69 kB
9
Indexable
import 'dart:async'; import 'dart:convert'; import 'package:app_client/data/model/rfood/new_rfood/get_pickup_status.dart'; import 'package:app_client/ui/config/colors.dart'; import 'package:app_client/ui/modules/runner_food/new_main/new_pickup/new_pickup_done.dart'; import 'package:app_client/ui/modules/runner_food/new_main/widget/animated_loading_bar.dart'; import 'package:app_client/ui/modules/runner_serviceride/widgets/my_separator.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:mapbox_gl/mapbox_gl.dart'; import 'package:provider/provider.dart'; import 'package:slider_button/slider_button.dart'; import '../ main_menu.dart'; import '../../../../../data/data_manager.dart'; import '../../../../../data/network/api_endpoint.dart'; import 'package:http/http.dart' as http; import '../../../../config/routes.dart'; import '../../../../state/rfood/a_new_rfood/add_to_cart_item/provider_add_to_cart.dart'; import '../../../../state/rfood/a_new_rfood/detail_resto_state/provider_detail_resto.dart'; import '../../../../state/rfood/a_new_rfood/keranjang_belanja_state/keranjang_belanja_state.dart'; import '../../../../state/rfood/a_new_rfood/provider_order_state/provider_order_state.dart'; import '../widget/utils.dart'; class NewPickUp extends StatefulWidget { const NewPickUp( {Key key, this.idMerchant, this.merchantLatitude, this.merchantLongitude, this.orderValue, this.value}) : super(key: key); final int idMerchant; final double merchantLatitude; final double merchantLongitude; final ProviderOrderState orderValue; final AddToCartProviderState value; @override State<NewPickUp> createState() => _NewPickUpState(); } class _NewPickUpState extends State<NewPickUp> { String statusText = ""; String descStatusText = ""; String imageStatus = ""; Color statusColor = white; int totalOrderedItem = 1; bool isSubmittedOrder = false; Timer _timer; bool isPreparing = false; bool isReady = false; bool isTake = false; bool isCompleted = false; MapboxMapController _mapController; int otherFees = 0; String getTime() { DateTime currentTime = DateTime.now(); String formattedTime = DateFormat("d MMMM yyyy hh:mm a").format(currentTime); return formattedTime; } void startStatusUpdateWhenWaiting() async { while (widget.orderValue.statusOrder != "WAITING") { await Future.delayed(Duration(seconds: 3)); } void startStatusUpdate() { _timer = Timer.periodic(Duration(seconds: 10), (_) { getDeliveryStatus(); changeStatus(); }); } startStatusUpdate(); } void stopUpdatingProgress() { _timer?.cancel(); } void changeStatus() { if (statusText == "PREPARING") { setState(() { isSubmittedOrder = true; descStatusText = "Hidangan sedang disiapkan"; imageStatus = "assets/images/cooking.png"; statusColor = Color(0xffF9C5AD); }); } if (statusText == "READY") { setState(() { isReady = true; descStatusText = "Pesanan anda sudah siap"; imageStatus = "assets/images/paper-bag.png"; statusColor = Color(0xffFADDAC); }); } else if (statusText == 'TAKE') { setState(() { isTake = true; descStatusText = "Pesanan anda sudah siap"; imageStatus = "assets/images/paper-bag.png"; statusColor = Color(0xffFADDAC); }); } else if (statusText == "COMPLETED") { setState(() { isCompleted = true; descStatusText = "Orderan anda siap disantap"; imageStatus = "assets/images/food-beverage.png"; statusColor = Color(0xff9DDDF7); }); } else if (statusText == "CANCELED") { stopUpdatingProgress(); } } Future<void> getDeliveryStatus() async { final url = Uri.parse(ApiEndPoint.rFoodPickUpStatus + "?ref_tracking=${widget.orderValue.refTrack}"); final response = await http.get( url, headers: <String, String>{'Authorization': 'Bearer $userToken'}, ); print("url: $url"); print("ref: ${widget.orderValue.refTrack}"); try { if (response.statusCode == 200) { final responseData = jsonDecode(response.body); final getStatus = GetPickUpStatus.fromJson(responseData); setState(() { statusText = getStatus.data.status; }); print("response : $responseData"); print("status order $statusText"); } else { print("failed get status : ${response.statusCode}"); } } catch (e) { print("error get status : $e"); } } String getStatusText() { String setStatusText = ""; switch (statusText) { case "PREPARING": setStatusText = "Siap Dalam"; break; case "READY": setStatusText = "Ambil Sebelum"; break; case "TAKE": setStatusText = "Ambil Sebelum"; break; case "COMPLETED": setStatusText = "Orderan Telah diambil"; break; default: setStatusText = ""; break; } return setStatusText; } @override void initState() { startStatusUpdateWhenWaiting(); super.initState(); } @override Widget build(BuildContext context) { return MultiProvider( providers: [ ChangeNotifierProvider<DetailRestoState>( create: (context) => DetailRestoState(widget.idMerchant), ), ChangeNotifierProvider<KeranjangBelanjaState>( create: (context) => KeranjangBelanjaState( widget.merchantLatitude, widget.merchantLongitude), ), ChangeNotifierProvider.value(value: widget.value), ChangeNotifierProvider<ProviderOrderState>( create: (context) => ProviderOrderState()), ], child: Consumer4<DetailRestoState, KeranjangBelanjaState, AddToCartProviderState, ProviderOrderState>( builder: (context, detail, keranjang, addItem, order, _) { final merchant = detail.listDetailMerchant.isNotEmpty ? detail.listDetailMerchant[0] : null; if (isSubmittedOrder == false || merchant == null || addItem.isLoading) { return Scaffold( body: Stack( children: [ Container( height: double.infinity, width: double.infinity, child: MapboxMap( initialCameraPosition: CameraPosition( target: LatLng(data.blocGps.myLocation.latitude, data.blocGps.myLocation.longitude), zoom: 16, ), onMapCreated: (MapboxMapController controller) { _mapController = controller; _mapController.animateCamera( CameraUpdate.newLatLngZoom( LatLng(widget.merchantLatitude, widget.merchantLongitude), 16.0, ), ); List<LatLng> polylineCoordinates = []; polylineCoordinates.add(LatLng( widget.merchantLatitude, widget.merchantLongitude)); polylineCoordinates.add(LatLng( data.blocGps.myLocation.latitude, data.blocGps.myLocation.longitude)); _mapController?.addLine( LineOptions( geometry: polylineCoordinates ?? [], lineColor: "#0000FF", lineWidth: 3, ), ); }, ), ), SafeArea( child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ InkWell( onTap: () { goReplace(context, MainMenu()); }, child: Container( height: 40, width: 40, margin: EdgeInsets.only(left: 20, top: 20), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(50), border: Border.all(color: Color(0xffEAEEF4)), ), child: Padding( padding: EdgeInsets.all(8.0), child: Icon( Icons.arrow_back_rounded, color: Colors.black, ), ), ), ), Container( height: 180, padding: EdgeInsets.all(20), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(10), ), child: Column( children: [ Center( child: Container( height: 5, width: 80, decoration: BoxDecoration( color: Colors.grey[300], borderRadius: BorderRadius.circular(10), ), ), ), SizedBox(height: 20), Row( children: [ CircularProgressIndicator( valueColor: AlwaysStoppedAnimation<Color>(primary), ), SizedBox(width: 20), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Memproses pesanan anda', style: TextStyle( color: Colors.black, fontSize: 14, fontWeight: FontWeight.w500, ), ), Text( 'Mohon tunggu, pesanan sedang di proses', style: TextStyle( color: Colors.black, fontSize: 12, fontWeight: FontWeight.w400, ), ), ], ), ], ), SizedBox(height: 20), Container( width: double.infinity, height: 50, child: ElevatedButton( onPressed: () { order.cancelOrder(order .listSubmitDeliveryOrder.trackingRef); back(context); }, style: ElevatedButton.styleFrom( backgroundColor: Color(0xffFCE5D6), elevation: 0, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), ), child: Text( "Batalkan Orderan", style: TextStyle( fontSize: 14, color: Color(0xffCB3A31), fontWeight: FontWeight.w600, ), ), ), ), ], ), ) ], ), ), ], ), ); } return Scaffold( body: Stack( children: [ Container( height: double.infinity, width: double.infinity, child: MapboxMap( initialCameraPosition: CameraPosition( target: LatLng(data.blocGps.myLocation.latitude, data.blocGps.myLocation.longitude), zoom: 16, ), onMapCreated: (MapboxMapController controller) { _mapController = controller; _mapController.animateCamera( CameraUpdate.newLatLngZoom( LatLng(widget.merchantLatitude, widget.merchantLongitude), 16.0, ), ); List<LatLng> polylineCoordinates = []; polylineCoordinates.add(LatLng( widget.merchantLatitude, widget.merchantLongitude)); polylineCoordinates.add(LatLng( data.blocGps.myLocation.latitude, data.blocGps.myLocation.longitude)); _mapController.addLine( LineOptions( geometry: polylineCoordinates, lineColor: "#0000FF", lineWidth: 3, ), ); }, ), ), SafeArea( child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ InkWell( onTap: () { // Navigator.push( // context, // MaterialPageRoute( // builder: (context) => NewKeranjangBelanja( // index: widget.index, // indexMenu: widget.indexMenu, // ), // ), // ); }, child: Container( height: 40, width: 40, margin: EdgeInsets.only(left: 20, top: 20), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(50), border: Border.all(color: Color(0xffEAEEF4)), ), child: Padding( padding: EdgeInsets.all(8.0), child: Icon( Icons.arrow_back_rounded, color: Colors.black, ), ), ), ), Expanded( child: DraggableScrollableSheet( initialChildSize: 0.45, minChildSize: 0.45, maxChildSize: 1, builder: (BuildContext context, ScrollController scrollController) { return Column( children: [ InkWell( onTap: () { _mapController.animateCamera( CameraUpdate.newLatLngZoom( LatLng(widget.merchantLatitude, widget.merchantLongitude), 16.0, ), ); }, child: Align( alignment: Alignment.topRight, child: Container( height: 35, width: 150, padding: EdgeInsets.all(5), margin: EdgeInsets.symmetric(horizontal: 20), decoration: BoxDecoration( color: Colors.white, border: Border.all( color: Color(0xffEAEEF4)), borderRadius: BorderRadius.circular(50), ), child: Row( children: [ Icon( Icons.my_location, color: Colors.black, size: 20, ), SizedBox(width: 10), Text( 'Tunjukkan Arah', style: TextStyle( color: Colors.black, fontSize: 12, fontWeight: FontWeight.w400, ), ), ], ), ), ), ), Container( width: double.infinity, height: 145, padding: EdgeInsets.all(20), margin: EdgeInsets.symmetric( horizontal: 20, vertical: 15), decoration: BoxDecoration( color: Colors.white, border: Border.all(color: Color(0xffEAEEF4)), borderRadius: BorderRadius.circular(10), ), child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( children: [ Icon( Icons.room_service, color: primary, size: 20, ), SizedBox(width: 10), isReady ? Container( width: 60, height: 5, decoration: BoxDecoration( color: primary, borderRadius: BorderRadius.circular( 50), ), ) : Expanded( child: AnimatedHorizontalLoadingBar(), ), SizedBox(width: 10), Icon( Icons.takeout_dining, color: isReady ? primary : Colors.grey[600], size: 20, ), SizedBox(width: 10), isReady == false ? Container( width: 60, height: 5, decoration: BoxDecoration( color: Colors.grey, borderRadius: BorderRadius.circular( 50), ), ) : isTake ? Container( width: 60, height: 5, decoration: BoxDecoration( color: primary, borderRadius: BorderRadius .circular(50), ), ) : Expanded( child: AnimatedHorizontalLoadingBar(), ), SizedBox(width: 10), Icon( Icons.directions_walk, color: isTake ? primary : Colors.grey[600], size: 20, ), SizedBox(width: 10), isTake == false ? Container( width: 60, height: 5, decoration: BoxDecoration( color: Colors.grey, borderRadius: BorderRadius.circular( 50), ), ) : isCompleted ? Container( width: 60, height: 5, decoration: BoxDecoration( color: primary, borderRadius: BorderRadius .circular(50), ), ) : Expanded( child: AnimatedHorizontalLoadingBar(), ), SizedBox(width: 10), Icon( Icons.store, color: isCompleted ? primary : Colors.grey[600], size: 20, ), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( getStatusText(), style: TextStyle( fontSize: 14, fontWeight: FontWeight.w500, ), ), Text( descStatusText, style: TextStyle( fontSize: 12, fontWeight: FontWeight.w400, ), ), ], ), Container( width: 60, height: 60, decoration: BoxDecoration( color: statusColor, borderRadius: BorderRadius.circular(100), ), child: Center( child: Image.asset( imageStatus, fit: BoxFit.cover, width: 30, ), ), ) ], ) ], )), Expanded( child: Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only( topLeft: Radius.circular(10), topRight: Radius.circular(10), ), ), child: ListView( controller: scrollController, children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Center( child: Container( width: 50, height: 2, margin: EdgeInsets.only(top: 20), decoration: BoxDecoration( borderRadius: BorderRadius.circular( 10), color: Color(0xff777777), ), ), ), Center( child: Container( width: 30, height: 2, margin: EdgeInsets.only(top: 5), decoration: BoxDecoration( borderRadius: BorderRadius.circular( 10), color: Color(0xff777777), ), ), ), SizedBox(height: 15), Padding( padding: EdgeInsets.only(left: 20), child: Text( "Order details", style: TextStyle( fontSize: 16, color: Colors.black, fontWeight: FontWeight.w600, ), ), ), SizedBox(height: 10), Row( children: [ Container( height: 60, margin: EdgeInsets.symmetric( horizontal: 20), width: 60, decoration: BoxDecoration( borderRadius: BorderRadius .circular(5), image: DecorationImage( image: NetworkImage( ApiEndPoint .pathMerchantPhoto + merchant .outletFoto), fit: BoxFit.cover, )), ), Text( merchant.outletName, maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 12, color: Colors.black, fontWeight: FontWeight.w500, ), ), ], ), Container( padding: EdgeInsets.all(20), margin: EdgeInsets.symmetric( horizontal: 20, vertical: 10), decoration: BoxDecoration( color: Color(0xffF9FAFC), border: Border( left: BorderSide( color: primary, width: 5))), child: ListView.builder( itemCount: addItem .listGetItem.length, physics: NeverScrollableScrollPhysics(), shrinkWrap: true, itemBuilder: (context, index) { final data = addItem .listGetItem[index]; return Container( margin: const EdgeInsets .symmetric( vertical: 10.0), child: Row( crossAxisAlignment: CrossAxisAlignment .start, children: [ Text( "${data.qtyCart}x", style: TextStyle( fontSize: 16, color: primary, fontWeight: FontWeight .w500, ), ), SizedBox( width: 20), Column( crossAxisAlignment: CrossAxisAlignment .start, children: [ Container( width: 250, child: Text( data.product .foodName, maxLines: 1, overflow: TextOverflow .ellipsis, style: TextStyle( fontSize: 14, color: Colors .black, fontWeight: FontWeight.w600, ), ), ), SizedBox( height: 5), Row( children: [ Text( "Add Ons : ", style: TextStyle( fontSize: 12, fontWeight: FontWeight.w600, color: Colors.black, ), ), Container( width: 150, child: Text( addItem.listAddsOnProduct.isNotEmpty ? addItem.getAddonsByProduct(index).join(", ") : "Tidak ada add ons", maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 12, fontWeight: FontWeight.w400, color: Colors.black, ), ), ), Text( data.addons.isNotEmpty ? "(+${addItem.getAddonsPriceByProduct(index)})" : "", style: TextStyle( fontSize: 12, fontWeight: FontWeight.w400, color: Colors.black, ), ), ], ), Row( children: [ Text( "Note : ", style: TextStyle( fontSize: 12, fontWeight: FontWeight.w600, color: Colors.black, ), ), Text( data.note == null || data.note == "" ? "Tidak ada catatan di produk ini" : data.note, style: TextStyle( fontSize: 12, fontWeight: FontWeight.w400, color: Colors.black, ), ) ], ), ], ) ], ), ); })), Container( margin: EdgeInsets.symmetric( horizontal: 20, vertical: 5), child: MySeparator( color: Color(0xffEAEEF4), width: 10, ), ), Container( margin: EdgeInsets.symmetric( horizontal: 20), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( "Order Summary", style: TextStyle( fontSize: 14, fontWeight: FontWeight.w500, color: Colors.black, ), ), SizedBox(height: 10), Row( mainAxisAlignment: MainAxisAlignment .spaceBetween, children: [ Text( "My Basket ", style: TextStyle( fontSize: 12, fontWeight: FontWeight.w400, color: Color( 0xff777777), ), ), Text( formatCurrency(addItem .totalHarga), style: TextStyle( fontSize: 12, fontWeight: FontWeight.w500, color: Color( 0xff4c4c4c), ), ), ], ), Row( mainAxisAlignment: MainAxisAlignment .spaceBetween, children: [ Text( "Other fees", style: TextStyle( fontSize: 12, fontWeight: FontWeight.w400, color: Color( 0xff777777), ), ), Text( formatCurrency( otherFees), style: TextStyle( fontSize: 12, fontWeight: FontWeight.w500, color: Color( 0xff4c4c4c), ), ), ], ), Row( mainAxisAlignment: MainAxisAlignment .spaceBetween, children: [ Text( "Promo", style: TextStyle( fontSize: 12, fontWeight: FontWeight.w400, color: Color( 0xff777777), ), ), Text( "Unapplied", style: TextStyle( fontSize: 12, fontWeight: FontWeight.w500, color: Color( 0xff4c4c4c), ), ), ], ), SizedBox(height: 10), MySeparator( color: Color(0xffEAEEF4), width: 10, ), SizedBox(height: 10), Row( mainAxisAlignment: MainAxisAlignment .spaceBetween, children: [ Text( "Total Payment", style: TextStyle( fontSize: 12, fontWeight: FontWeight.w400, color: Color( 0xff777777), ), ), Text( formatCurrency(addItem .totalHarga + otherFees), style: TextStyle( fontSize: 12, fontWeight: FontWeight.w500, color: Color( 0xff4c4c4c), ), ), ], ), SizedBox(height: 5), Row( mainAxisAlignment: MainAxisAlignment .spaceBetween, children: [ Text( "Payment Methode", style: TextStyle( fontSize: 12, fontWeight: FontWeight.w400, color: Color( 0xff777777), ), ), Text( detail.selectedOptionCashWallet == 0 ? "Cash" : "Wallet", style: TextStyle( fontSize: 12, fontWeight: FontWeight .w500, color: detail .selectedOptionCashWallet == 0 ? Color( 0xff43936C) : primary), ), ], ), ], ), ), Container( margin: EdgeInsets.symmetric( horizontal: 20, vertical: 10), padding: EdgeInsets.all(20), decoration: BoxDecoration( color: Color(0xffF9FAFC), borderRadius: BorderRadius.circular( 10), border: Border.all( color: Color(0xffF1F4F8))), child: Row( mainAxisAlignment: MainAxisAlignment .spaceBetween, children: [ Container( width: 250, child: Column( crossAxisAlignment: CrossAxisAlignment .start, children: [ Text( "Have any question?", style: TextStyle( fontSize: 12, fontWeight: FontWeight .w600, color: Color( 0xff313131), ), ), SizedBox(height: 5), Text( "Here some frequently asked question by customer", maxLines: 2, style: TextStyle( fontSize: 12, fontWeight: FontWeight .w400, color: Color( 0xff313131), ), ), ], ), ), Icon( Icons .arrow_forward_ios_rounded, color: Color(0xff4C4C4C), ) ], ), ), const SizedBox( height: 30.0, ), ], ), ], )), ), ], ); }, ), ), ], ), ), ], ), floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, floatingActionButton: isTake ? SliderButton( action: () { setState(() { isCompleted = true; }); stopUpdatingProgress(); Navigator.push( context, MaterialPageRoute( builder: (context) => NewPickUpDone( idMerchant: widget.idMerchant, idCart: addItem.getIdCart(), merchantLatitude: widget.merchantLatitude, merchantLongitude: widget.merchantLongitude, timeStamp: getTime(), refTracking: widget.orderValue.refTrack, ))); }, label: Text( 'Geser apabila order telah diterima', style: TextStyle( color: Colors.white, fontWeight: FontWeight.w500, fontSize: 12.0, ), ), icon: Icon( Icons.keyboard_double_arrow_right_rounded, color: Color(0xff252A3C), size: 30.0, ), width: 350.0, buttonColor: Colors.white, backgroundColor: primary, ) : Container()); }), ); } }
Editor is loading...
Leave a Comment