Files
rog_app/lib/widgets/destination_widget.dart

269 lines
11 KiB
Dart
Raw Normal View History

2022-05-24 20:43:41 +05:30
import 'package:flutter/material.dart';
2022-06-14 14:37:59 +05:30
import 'package:geojson/geojson.dart';
2022-05-24 20:43:41 +05:30
import 'package:get/get.dart';
2022-07-09 22:51:34 +05:30
import 'package:rogapp/model/destination.dart';
2022-05-24 20:43:41 +05:30
import 'package:rogapp/pages/destination/destination_controller.dart';
import 'package:rogapp/pages/index/index_controller.dart';
2022-11-05 22:02:21 +05:30
import 'package:rogapp/utils/const.dart';
2022-09-22 20:36:56 +05:30
import 'package:rogapp/utils/database_helper.dart';
2022-06-27 12:15:54 +05:30
import 'package:rogapp/widgets/bottom_sheet_new.dart';
2022-06-14 14:37:59 +05:30
import 'package:rogapp/widgets/bottom_sheet_widget.dart';
import 'package:sqflite/sqlite_api.dart';
2022-05-24 20:43:41 +05:30
import 'package:timeline_tile/timeline_tile.dart';
class DestinationWidget extends StatelessWidget {
DestinationWidget({ Key? key }) : super(key: key);
final DestinationController destinationController = Get.find<DestinationController>();
final IndexController indexController = Get.find<IndexController>();
final List<int> _items = List<int>.generate(50, (int index) => index);
Image getImage(int index){
2022-07-09 22:51:34 +05:30
if(destinationController.destinations[index].photos== null || destinationController.destinations[index].photos == ""){
2022-05-24 20:43:41 +05:30
return Image(image: AssetImage('assets/images/empty_image.png'));
}
else{
2022-07-14 23:10:24 +05:30
print("------- image is ${destinationController.destinations[index].photos!}------");
2022-09-29 15:32:33 +05:30
String _photo = destinationController.destinations[index].photos!;
if(_photo.contains('http')){
return Image(image: NetworkImage(
destinationController.destinations[index].photos!),
errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) {
return Image.asset("assets/images/empty_image.png");
},
);
}
else {
2022-11-05 22:02:21 +05:30
String server_url = ConstValues.currentServer();
2022-09-29 15:32:33 +05:30
return Image(image: NetworkImage(
2022-11-05 22:02:21 +05:30
'${server_url}/media/' + destinationController.destinations[index].photos!),
2022-09-29 15:32:33 +05:30
errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) {
return Image.asset("assets/images/empty_image.png");
},
);
}
2022-05-24 20:43:41 +05:30
}
}
2022-10-30 21:43:29 +05:30
// bool getSelection(int index){
// bool ret = false;
// destinationController.destination_index_data.forEach((element) {
// if(index == element["index"]){
// if(element["selected"] == true){
// ret = true;
// return;
// }
// }
// });
// return ret;
// }
2022-05-25 21:00:10 +05:30
void doDelete() {
2022-07-10 23:50:43 +05:30
destinationController.currentSelectedDestinations.forEach((element) {
destinationController.deleteDestination(element);
2022-10-30 21:43:29 +05:30
destinationController.resetRogaining();
2022-05-25 21:00:10 +05:30
});
2022-07-10 23:50:43 +05:30
// destinationController.destination_index_data.forEach((element) {
// //print(element["index"]);
// destinationController.deleteDestination(element["index"]);
// });
2022-05-25 21:00:10 +05:30
// destinationController.destination_index_data.clear();
}
void moveUp() {
2022-09-23 18:40:17 +05:30
Destination? d = null;
for(Destination ad in destinationController.destinations){
if(ad.selected == true){
d = ad;
break;
}
}
if(d != null){
print("--- selected destination is ${d.list_order}");
destinationController.makeOrder(d, -1);
2022-09-22 20:36:56 +05:30
}
2022-05-25 21:00:10 +05:30
}
void moveDown() {
2022-09-23 18:40:17 +05:30
Destination? d = null;
for(Destination ad in destinationController.destinations){
if(ad.selected == true){
d = ad;
break;
}
}
if(d != null){
print("--- selected destination is ${d.list_order}");
destinationController.makeOrder(d, 1);
}
}
void clearall(){
Get.defaultDialog(
title: "are_you_sure_want_to_delete_all".tr,
middleText: "all_added_destination_will_be_deleted".tr,
backgroundColor: Colors.blue.shade300,
titleStyle: TextStyle(color: Colors.white),
middleTextStyle: TextStyle(color: Colors.white),
textConfirm: "confirm".tr,
textCancel: "cancel".tr,
cancelTextColor: Colors.white,
confirmTextColor: Colors.blue,
buttonColor: Colors.white,
barrierDismissible: false,
radius: 10,
content: Column(
children: [
],
),
onConfirm: (){
destinationController.deleteAllDestinations();
Get.back();
Get.snackbar("deleted".tr, "all_destinations_are_deleted_successfully".tr);
}
);
2022-05-25 21:00:10 +05:30
}
void interChange() {
2022-07-09 22:51:34 +05:30
// int first_index = -1;
// destinationController.destination_index_data.forEach((element) {
// //print(element["index"]);
// int action_id = destinationController.destinations[element["index"]]["id"] as int;
// destinationController.makeOrder(action_id, (element["index"] as int) + 1, "up");
2022-06-04 20:16:29 +05:30
2022-07-09 22:51:34 +05:30
// });
2022-05-25 21:00:10 +05:30
}
2022-09-22 20:36:56 +05:30
Future getIsLocationAvilable(int location_id) async {
DatabaseHelper db = DatabaseHelper.instance;
return await db.isAlreadyAvailable(location_id);
}
2022-05-24 20:43:41 +05:30
@override
Widget build(BuildContext context) {
2022-07-09 22:51:34 +05:30
2022-07-10 23:50:43 +05:30
print("------ destination widget------ ${destinationController.destinationCount.value} ----------");
2022-07-09 22:51:34 +05:30
2022-05-24 20:43:41 +05:30
return
2022-05-25 21:00:10 +05:30
Obx(() =>
Stack(
children: [
Padding(
padding: const EdgeInsets.only(top:45.0),
child: ListView.builder(
2022-06-29 18:25:19 +05:30
itemCount: destinationController.destinationCount.value,
2022-05-25 21:00:10 +05:30
itemBuilder: (BuildContext context, int index) {
return
TimelineTile(
alignment: TimelineAlign.manual,
lineXY: 0.2,
isFirst: index == 0 ? true : false,
indicatorStyle: IndicatorStyle(
2022-09-22 20:36:56 +05:30
indicator: CircleAvatar(
child: Text(destinationController.destinations[index].list_order.toString(), style: TextStyle(color: Colors.white),),
backgroundColor: Colors.red,
),
2022-05-25 21:00:10 +05:30
),
key: Key(index.toString()),
endChild: Card(
child: Container(
constraints: const BoxConstraints(
minHeight: 80,
),
child: ListTile(
2022-06-14 14:37:59 +05:30
onTap: () async {
{
2022-07-14 23:10:24 +05:30
Destination? fs = destinationController.destinations[index];
print("----fsf-----${index}");
2022-06-14 14:37:59 +05:30
if(fs != null){
2022-07-14 23:10:24 +05:30
2022-10-30 21:43:29 +05:30
if(indexController.currentDestinationFeature.isNotEmpty) {
2022-07-09 22:51:34 +05:30
indexController.currentDestinationFeature.clear();
2022-06-14 14:37:59 +05:30
}
2022-07-09 22:51:34 +05:30
indexController.currentDestinationFeature.add(fs);
2022-10-30 21:43:29 +05:30
print("--- ndexController.currentDestinationFeature ----- ${ indexController.currentDestinationFeature[0].name} ----");
2022-07-09 22:51:34 +05:30
//indexController.getAction();
2022-06-14 14:37:59 +05:30
showModalBottomSheet(context: context, isScrollControlled: true,
2022-06-27 12:15:54 +05:30
//builder:((context) => BottomSheetWidget())
builder:((context) => BottomSheetNew())
2022-06-14 14:37:59 +05:30
);
}
};
},
2022-05-25 21:00:10 +05:30
onLongPress: (){
destinationController.toggleSelection(destinationController.destinations[index]);
2022-05-25 21:00:10 +05:30
},
selectedTileColor: Colors.amberAccent,
2022-07-14 23:10:24 +05:30
selected:destinationController.destinations[index].selected!,
2022-05-25 21:00:10 +05:30
leading: getImage(index),
2022-07-09 22:51:34 +05:30
title: Text(destinationController.destinations[index].name!),
2022-07-10 23:50:43 +05:30
subtitle: Text(destinationController.destinations[index].category!),
2022-05-25 21:00:10 +05:30
),
),
),
2022-06-29 18:25:19 +05:30
startChild:
2022-09-29 15:32:33 +05:30
index > 0 && destinationController.matrix["routes"][0]["legs"] != null ?
2022-06-29 18:25:19 +05:30
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
2022-09-29 15:32:33 +05:30
Text(destinationController.matrix["routes"][0]["legs"][index -1]["distance"] != null ? destinationController.matrix["routes"][0]["legs"][index-1]["distance"]["text"].toString(): ''),
Text(destinationController.matrix["routes"][0]["legs"][index -1]["duration"] != null ? destinationController.matrix["routes"][0]["legs"][index-1]["duration"]["text"].toString() : '')
2022-06-29 18:25:19 +05:30
],
):
Container()
,
2022-05-24 20:43:41 +05:30
);
2022-05-25 21:00:10 +05:30
}
2022-05-24 20:43:41 +05:30
),
),
2022-05-25 21:00:10 +05:30
Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.3),
spreadRadius: 5,
blurRadius: 3,
offset: Offset(0, 7), // changes position of shadow
),
],
),
height: 44.0,
width: MediaQuery.of(context).size.width,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
2022-09-23 18:40:17 +05:30
IconButton(
icon:Icon(Icons.delete_forever),
//onPressed: (){doDelete();},
onPressed: clearall,
),
2022-05-25 21:00:10 +05:30
IconButton(
icon:Icon(Icons.cancel),
//onPressed: (){doDelete();},
2022-07-10 23:50:43 +05:30
onPressed: destinationController.currentSelectedDestinations.length > 0 ? doDelete : null,
2022-05-25 21:00:10 +05:30
),
IconButton(
icon:Icon(Icons.move_up),
2022-09-23 18:40:17 +05:30
onPressed: destinationController.currentSelectedDestinations.length > 0 ? moveUp : null,
2022-05-25 21:00:10 +05:30
),
IconButton(
icon:Icon(Icons.move_down),
2022-09-23 18:40:17 +05:30
onPressed: destinationController.currentSelectedDestinations.length > 0 ? moveDown : null,
2022-05-25 21:00:10 +05:30
),
2022-09-23 18:40:17 +05:30
// IconButton(
// icon:Icon(Icons.sync),
// onPressed: destinationController.destination_index_data.length == 2 ? interChange : null,
// ),
2022-05-25 21:00:10 +05:30
],
),
)
],
)
2022-05-24 20:43:41 +05:30
);
}
}