update
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:rogapp/pages/destination/destination_controller.dart';
|
||||
@ -22,66 +24,153 @@ class DestinationWidget extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void doDelete() {
|
||||
destinationController.destination_index_data.forEach((element) {
|
||||
//print(element["index"]);
|
||||
destinationController.deleteDestination(element["index"]);
|
||||
});
|
||||
// destinationController.destination_index_data.clear();
|
||||
}
|
||||
|
||||
void moveUp() {
|
||||
|
||||
}
|
||||
|
||||
void moveDown() {
|
||||
|
||||
}
|
||||
|
||||
void interChange() {
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return
|
||||
ReorderableListView.builder(
|
||||
|
||||
itemCount: destinationController.destinations.length,
|
||||
onReorder: (int oldIndex, int newIndex){
|
||||
int action_id = destinationController.destinations[oldIndex]["id"] as int;
|
||||
//print(action_id);
|
||||
if(oldIndex > newIndex){
|
||||
destinationController.makeOrder(context, action_id, newIndex, "up");
|
||||
}
|
||||
else if(oldIndex < newIndex){
|
||||
destinationController.makeOrder(context, action_id, newIndex, "down");
|
||||
}
|
||||
|
||||
},
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return TimelineTile(
|
||||
alignment: TimelineAlign.manual,
|
||||
lineXY: 0.2,
|
||||
isFirst: index == 0 ? true : false,
|
||||
indicatorStyle: IndicatorStyle(
|
||||
color: index == 0 ? (Colors.red) : (Colors.grey[400])!
|
||||
),
|
||||
key: Key(index.toString()),
|
||||
endChild: Card(
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: 80,
|
||||
),
|
||||
child: ListTile(
|
||||
onLongPress: (){
|
||||
print("----- selected index ${index}");
|
||||
var el = destinationController.destination_index_data.where((element) =>
|
||||
element["index"] == index
|
||||
Obx(() =>
|
||||
Stack(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top:45.0),
|
||||
child: ListView.builder(
|
||||
itemCount: destinationController.destinations.length,
|
||||
// onReorder: (int oldIndex, int newIndex){
|
||||
// int action_id = destinationController.destinations[oldIndex]["id"] as int;
|
||||
// //print(action_id);
|
||||
// if(oldIndex > newIndex){
|
||||
// destinationController.makeOrder(context, action_id, newIndex, "up");
|
||||
// }
|
||||
// else if(oldIndex < newIndex){
|
||||
// destinationController.makeOrder(context, action_id, newIndex, "down");
|
||||
// }
|
||||
|
||||
// },
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return
|
||||
TimelineTile(
|
||||
alignment: TimelineAlign.manual,
|
||||
lineXY: 0.2,
|
||||
isFirst: index == 0 ? true : false,
|
||||
indicatorStyle: IndicatorStyle(
|
||||
color: index == 0 ? (Colors.red) : (Colors.grey[400])!
|
||||
),
|
||||
key: Key(index.toString()),
|
||||
endChild: Card(
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: 80,
|
||||
),
|
||||
child: ListTile(
|
||||
onLongPress: (){
|
||||
print("#### long press #### ${destinationController.destination_index_data.length}");
|
||||
|
||||
var match_element = null;
|
||||
destinationController.destination_index_data.forEach((element) {
|
||||
if(element["index"] == index){
|
||||
match_element = element;
|
||||
print("----match----");
|
||||
return;
|
||||
}
|
||||
});
|
||||
if(match_element != null){
|
||||
destinationController.destination_index_data.remove(match_element);
|
||||
return;
|
||||
}
|
||||
//print("------${destinationController.destination_index_data}----");
|
||||
Map<String, dynamic> indexed = {'index': index, 'selected':true};
|
||||
destinationController.destination_index_data.add(indexed);
|
||||
},
|
||||
selectedTileColor: Colors.amberAccent,
|
||||
selected:getSelection(index),
|
||||
leading: getImage(index),
|
||||
title: Text(destinationController.destinations[index]["location"]["properties"]["location_name"]),
|
||||
subtitle: Text(destinationController.destinations[index]["location"]["properties"]["category"]),
|
||||
),
|
||||
),
|
||||
),
|
||||
startChild: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Text(destinationController.matrix["rows"][0]["elements"][index]["distance"]["text"].toString()),
|
||||
Text(destinationController.matrix["rows"][0]["elements"][index]["duration"]["text"].toString())
|
||||
],
|
||||
),
|
||||
);
|
||||
if(el != null){
|
||||
destinationController.destination_index_data.remove(el);
|
||||
}
|
||||
print("------${el}---- index ${index}");
|
||||
Map<String, dynamic> indexed = {'index': index, 'selected':true};
|
||||
destinationController.destination_index_data.add(indexed);
|
||||
},
|
||||
leading: getImage(index),
|
||||
title: Text(destinationController.destinations[index]["location"]["properties"]["location_name"]),
|
||||
subtitle: Text(destinationController.destinations[index]["location"]["properties"]["category"]),
|
||||
|
||||
}
|
||||
),
|
||||
),
|
||||
|
||||
),
|
||||
startChild: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Text(destinationController.matrix["rows"][0]["elements"][index]["distance"]["text"].toString()),
|
||||
Text(destinationController.matrix["rows"][0]["elements"][index]["duration"]["text"].toString())
|
||||
],
|
||||
),
|
||||
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: [
|
||||
IconButton(
|
||||
icon:Icon(Icons.cancel),
|
||||
//onPressed: (){doDelete();},
|
||||
onPressed: destinationController.destination_index_data.length > 0 ? doDelete : null,
|
||||
),
|
||||
IconButton(
|
||||
icon:Icon(Icons.move_up),
|
||||
onPressed: destinationController.destination_index_data.length > 0 ? moveUp : null,
|
||||
),
|
||||
IconButton(
|
||||
icon:Icon(Icons.move_down),
|
||||
onPressed: destinationController.destination_index_data.length > 0 ? moveDown : null,
|
||||
),
|
||||
IconButton(
|
||||
icon:Icon(Icons.sync),
|
||||
onPressed: destinationController.destination_index_data.length == 2 ? interChange : null,
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user