Skip to content

Commit

Permalink
add comparison location
Browse files Browse the repository at this point in the history
  • Loading branch information
Student authored and Student committed Apr 23, 2024
1 parent 880ad45 commit 2eb87c2
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 28 deletions.
6 changes: 3 additions & 3 deletions lib/feature/data/datasources/order_remote_data_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ abstract class OrderRemoteDataSource {
Future<List<OrderModel>> getUserOrdersByDateRange(
DateTime start, DateTime end,
{bool? isDelivered});
RealtimeChannel listenToUserOrdersChanges(String channel, void Function() callback);
RealtimeChannel listenToUserOrdersChanges(
String channel, void Function() callback);
}

class OrderRemoteDataSourceImpl implements OrderRemoteDataSource {
Expand Down Expand Up @@ -52,10 +53,9 @@ class OrderRemoteDataSourceImpl implements OrderRemoteDataSource {

@override
Future<void> setOrderIsDelivered(int id, bool isDelivered) async {

final List<Map<String, dynamic>> data = await supabaseClient
.from("Orders")
.update({'is_delivered': isDelivered, 'delivery_date': DateTime.now()})
.update({'is_delivered': isDelivered})
.eq('order_number', id)
.select();
print('data --> $data');
Expand Down
108 changes: 83 additions & 25 deletions lib/feature/presentation/pages/order_detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:beFit_Del/feature/presentation/bloc/set_delivered_cubit/set_deli
import 'package:beFit_Del/feature/presentation/widgets/item_list_widget.dart';
import 'package:swipeable_button_view/swipeable_button_view.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:geolocator/geolocator.dart';

class OrderDetailPage extends StatefulWidget {
const OrderDetailPage({super.key});
Expand Down Expand Up @@ -41,6 +42,8 @@ class _OrderDetailPageState extends State<OrderDetailPage> {
BitmapDescriptor.fromAssetImage(ImageConfiguration.empty, "assets/home.png")
.then((icon) => home = icon);

List<double> locationList = [];

void launchGoogleMapsNavigation(double startLat, double startLong,
double destinationLat, double destinationLong) async {
// Начальная точка
Expand Down Expand Up @@ -237,7 +240,18 @@ class _OrderDetailPageState extends State<OrderDetailPage> {
children: [
IconButton(
iconSize: 30,
onPressed: () {},
onPressed: () async {
String telephoneNumber = order.clientPhone;
String telephoneUrl =
"tel:$telephoneNumber";
// ignore: deprecated_member_use
if (await canLaunch(telephoneUrl)) {
// ignore: deprecated_member_use
await launch(telephoneUrl);
} else {
throw "Error occured trying to call that number.";
}
},
icon: const Icon(Icons.phone_in_talk_rounded),
color: Colors.black,
),
Expand All @@ -259,7 +273,18 @@ class _OrderDetailPageState extends State<OrderDetailPage> {
children: [
IconButton(
iconSize: 30,
onPressed: () {},
onPressed: () async {
String telephoneNumber = '+2347012345678';
String telephoneUrl =
"tel:$telephoneNumber";
// ignore: deprecated_member_use
if (await canLaunch(telephoneUrl)) {
// ignore: deprecated_member_use
await launch(telephoneUrl);
} else {
throw "Error occured trying to call that number.";
}
},
icon: const Icon(Icons.phone),
color: Colors.black,
),
Expand Down Expand Up @@ -316,9 +341,6 @@ class _OrderDetailPageState extends State<OrderDetailPage> {
bottom: 10,
),
child: GestureDetector(
onTap: () {
Navigator.of(context).pushNamed('/statistics');
},
child: Row(
// crossAxisAlignment: CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.max,
Expand Down Expand Up @@ -385,23 +407,6 @@ class _OrderDetailPageState extends State<OrderDetailPage> {
}
},
),
BlocListener<SetDeliveredCubit, SetDeliveredState>(
listener: (context, state) {
if (state is SetDeliveredLoaded) {
print('orderId $orderId, \n isdelivered true');
Navigator.pop(context);
Navigator.pushNamed(context, "/orders");
} else if (state is SetDeliveredError) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Ошибка!'),
backgroundColor: Colors.redAccent,
),
);
}
},
child: const SizedBox(),
),
],
),
const Divider(color: Color(0xFFAFA8A1)),
Expand Down Expand Up @@ -549,13 +554,66 @@ class _OrderDetailPageState extends State<OrderDetailPage> {
isFinished: isFinished,
onWaitingProcess: () {
Future.delayed(Duration(seconds: 2), () {
context
.read<SetDeliveredCubit>()
.setOrderIsDelivered(orderId, true);
final double radius = 150; // Радиус в метрах
final distance = Geolocator.distanceBetween(
locationList[0],
locationList[1],
locationList[2],
locationList[3]);
if (distance <= radius) {
context
.read<SetDeliveredCubit>()
.setOrderIsDelivered(orderId, true);
} else {
isFinished = false;
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content:
Text('Вы не в радиусе заказа!'),
backgroundColor: Colors.redAccent,
),
);
}
});
},
onFinish: () async {}),
),
BlocListener<SetDeliveredCubit, SetDeliveredState>(
listener: (context, state) {
if (state is SetDeliveredLoaded) {
print('orderId $orderId, \n isdelivered true');
Navigator.pop(context);
Navigator.pushNamed(context, "/orders");
} else if (state is SetDeliveredError) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Ошибка!'),
backgroundColor: Colors.redAccent,
),
);
}
},
child: const SizedBox(),
),
BlocListener<LocationCubit, LocationState>(
listener: (context, state) {
if (state is GetLocationSuccessState) {
locationList.add(state.position.locations[0].latitude);
locationList.add(state.position.locations[0].longitude);
locationList.add(state.position.phone.latitude);
locationList.add(state.position.phone.longitude);
print('${locationList[0]}');
} else if (state is GetLocationFailState) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Ошибка загрузка геолокации'),
backgroundColor: Colors.redAccent,
),
);
}
},
child: const SizedBox(),
),
],
)),
),
Expand Down

0 comments on commit 2eb87c2

Please sign in to comment.