map picker, firebase improvement and changes for v2.5
parent
14b0c4c125
commit
e3bf988df5
@ -1,390 +1,390 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:diplomaticquarterapp/models/LiveCare/room_model.dart';
|
||||
import 'package:diplomaticquarterapp/pages/conference/conference_button_bar.dart';
|
||||
import 'package:diplomaticquarterapp/pages/conference/conference_room.dart';
|
||||
import 'package:diplomaticquarterapp/pages/landing/landing_page.dart';
|
||||
import 'package:diplomaticquarterapp/pages/conference/draggable_publisher.dart';
|
||||
import 'package:diplomaticquarterapp/pages/conference/participant_widget.dart';
|
||||
import 'package:diplomaticquarterapp/pages/conference/widgets/noise_box.dart';
|
||||
import 'package:diplomaticquarterapp/pages/conference/widgets/platform_alert_dialog.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:wakelock/wakelock.dart';
|
||||
|
||||
class ConferencePage extends StatefulWidget {
|
||||
final RoomModel roomModel;
|
||||
|
||||
const ConferencePage({Key key, this.roomModel}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ConferencePageState createState() => _ConferencePageState();
|
||||
}
|
||||
|
||||
class _ConferencePageState extends State<ConferencePage> {
|
||||
final StreamController<bool> _onButtonBarVisibleStreamController = StreamController<bool>.broadcast();
|
||||
final StreamController<double> _onButtonBarHeightStreamController = StreamController<double>.broadcast();
|
||||
ConferenceRoom _conferenceRoom;
|
||||
StreamSubscription _onConferenceRoomException;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_lockInPortrait();
|
||||
_connectToRoom();
|
||||
_wakeLock(true);
|
||||
}
|
||||
|
||||
void _connectToRoom() async {
|
||||
try {
|
||||
final conferenceRoom = ConferenceRoom(
|
||||
name: widget.roomModel.name,
|
||||
token: widget.roomModel.token,
|
||||
identity: widget.roomModel.identity,
|
||||
);
|
||||
await conferenceRoom.connect();
|
||||
setState(() {
|
||||
_conferenceRoom = conferenceRoom;
|
||||
_onConferenceRoomException = _conferenceRoom.onException.listen((err) async {
|
||||
await PlatformAlertDialog(
|
||||
title: err is PlatformException ? err.message : 'An error occured',
|
||||
content: err is PlatformException ? err.details : err.toString(),
|
||||
defaultActionText: 'OK',
|
||||
).show(context);
|
||||
});
|
||||
_conferenceRoom.addListener(_conferenceRoomUpdated);
|
||||
});
|
||||
} catch (err) {
|
||||
print(err);
|
||||
await PlatformAlertDialog(
|
||||
title: err is PlatformException ? err.message : 'An error occured',
|
||||
content: err is PlatformException ? err.details : err.toString(),
|
||||
defaultActionText: 'OK',
|
||||
).show(context);
|
||||
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _lockInPortrait() async {
|
||||
await SystemChrome.setPreferredOrientations(<DeviceOrientation>[
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_freePortraitLock();
|
||||
_wakeLock(false);
|
||||
_disposeStreamsAndSubscriptions();
|
||||
if (_conferenceRoom != null) _conferenceRoom.removeListener(_conferenceRoomUpdated);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _freePortraitLock() async {
|
||||
await SystemChrome.setPreferredOrientations(<DeviceOrientation>[
|
||||
DeviceOrientation.landscapeRight,
|
||||
DeviceOrientation.landscapeLeft,
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
}
|
||||
|
||||
Future<void> _disposeStreamsAndSubscriptions() async {
|
||||
if (_onButtonBarVisibleStreamController != null) await _onButtonBarVisibleStreamController.close();
|
||||
if (_onButtonBarHeightStreamController != null) await _onButtonBarHeightStreamController.close();
|
||||
if (_onConferenceRoomException != null) await _onConferenceRoomException.cancel();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return WillPopScope(
|
||||
onWillPop: () async => false,
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
body: _conferenceRoom == null ? showProgress() : buildLayout(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
LayoutBuilder buildLayout() {
|
||||
return LayoutBuilder(
|
||||
builder: (BuildContext context, BoxConstraints constraints) {
|
||||
return Stack(
|
||||
children: <Widget>[
|
||||
_buildParticipants(context, constraints.biggest, _conferenceRoom),
|
||||
ConferenceButtonBar(
|
||||
audioEnabled: _conferenceRoom.onAudioEnabled,
|
||||
videoEnabled: _conferenceRoom.onVideoEnabled,
|
||||
onAudioEnabled: _conferenceRoom.toggleAudioEnabled,
|
||||
onVideoEnabled: _conferenceRoom.toggleVideoEnabled,
|
||||
onHangup: _onHangup,
|
||||
onSwitchCamera: _conferenceRoom.switchCamera,
|
||||
onPersonAdd: _onPersonAdd,
|
||||
onPersonRemove: _onPersonRemove,
|
||||
onHeight: _onHeightBar,
|
||||
onShow: _onShowBar,
|
||||
onHide: _onHideBar,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget showProgress() {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Center(child: CircularProgressIndicator()),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Text(
|
||||
'Connecting to the call...',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onHangup() async {
|
||||
print('onHangup');
|
||||
await _conferenceRoom.disconnect();
|
||||
LandingPage.isOpenCallPage = false;
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
void _onPersonAdd() {
|
||||
print('onPersonAdd');
|
||||
try {
|
||||
_conferenceRoom.addDummy(
|
||||
child: Stack(
|
||||
children: <Widget>[
|
||||
const Placeholder(),
|
||||
Center(
|
||||
child: Text(
|
||||
(_conferenceRoom.participants.length + 1).toString(),
|
||||
style: const TextStyle(
|
||||
shadows: <Shadow>[
|
||||
Shadow(
|
||||
blurRadius: 3.0,
|
||||
color: Color.fromARGB(255, 0, 0, 0),
|
||||
),
|
||||
Shadow(
|
||||
blurRadius: 8.0,
|
||||
color: Color.fromARGB(255, 255, 255, 255),
|
||||
),
|
||||
],
|
||||
fontSize: 80,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} on PlatformException catch (err) {
|
||||
PlatformAlertDialog(
|
||||
title: err.message,
|
||||
content: err.details,
|
||||
defaultActionText: 'OK',
|
||||
).show(context);
|
||||
}
|
||||
}
|
||||
|
||||
void _onPersonRemove() {
|
||||
print('onPersonRemove');
|
||||
_conferenceRoom.removeDummy();
|
||||
}
|
||||
|
||||
Widget _buildParticipants(BuildContext context, Size size, ConferenceRoom conferenceRoom) {
|
||||
final children = <Widget>[];
|
||||
final length = conferenceRoom.participants.length;
|
||||
|
||||
if (length <= 2) {
|
||||
_buildOverlayLayout(context, size, children);
|
||||
return Stack(children: children);
|
||||
}
|
||||
|
||||
void buildInCols(bool removeLocalBeforeChunking, bool moveLastOfEachRowToNextRow, int columns) {
|
||||
_buildLayoutInGrid(
|
||||
context,
|
||||
size,
|
||||
children,
|
||||
removeLocalBeforeChunking: removeLocalBeforeChunking,
|
||||
moveLastOfEachRowToNextRow: moveLastOfEachRowToNextRow,
|
||||
columns: columns,
|
||||
);
|
||||
}
|
||||
|
||||
// if (length <= 3) {
|
||||
// buildInCols(true, false, 1);
|
||||
// } else if (length == 5) {
|
||||
// buildInCols(false, true, 2);
|
||||
// } else if (length <= 6 || length == 8) {
|
||||
// buildInCols(false, false, 2);
|
||||
// } else if (length == 7 || length == 9) {
|
||||
// buildInCols(true, false, 2);
|
||||
// } else if (length == 10) {
|
||||
// buildInCols(false, true, 3);
|
||||
// } else if (length == 13 || length == 16) {
|
||||
// buildInCols(true, false, 3);
|
||||
// } else if (length <= 18) {
|
||||
// buildInCols(false, false, 3);
|
||||
// }
|
||||
|
||||
return Column(
|
||||
children: children,
|
||||
);
|
||||
}
|
||||
|
||||
void _buildOverlayLayout(BuildContext context, Size size, List<Widget> children) {
|
||||
final participants = _conferenceRoom.participants;
|
||||
if (participants.length == 1) {
|
||||
children.add(_buildNoiseBox());
|
||||
} else {
|
||||
final remoteParticipant = participants.firstWhere((ParticipantWidget participant) => participant.isRemote, orElse: () => null);
|
||||
if (remoteParticipant != null) {
|
||||
children.add(remoteParticipant);
|
||||
}
|
||||
}
|
||||
|
||||
final localParticipant = participants.firstWhere((ParticipantWidget participant) => !participant.isRemote, orElse: () => null);
|
||||
if (localParticipant != null) {
|
||||
children.add(DraggablePublisher(
|
||||
key: Key('publisher'),
|
||||
child: localParticipant,
|
||||
availableScreenSize: size,
|
||||
onButtonBarVisible: _onButtonBarVisibleStreamController.stream,
|
||||
onButtonBarHeight: _onButtonBarHeightStreamController.stream,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
void _buildLayoutInGrid(
|
||||
BuildContext context,
|
||||
Size size,
|
||||
List<Widget> children, {
|
||||
bool removeLocalBeforeChunking = false,
|
||||
bool moveLastOfEachRowToNextRow = false,
|
||||
int columns = 2,
|
||||
}) {
|
||||
final participants = _conferenceRoom.participants;
|
||||
ParticipantWidget localParticipant;
|
||||
if (removeLocalBeforeChunking) {
|
||||
localParticipant = participants.firstWhere((ParticipantWidget participant) => !participant.isRemote, orElse: () => null);
|
||||
if (localParticipant != null) {
|
||||
participants.remove(localParticipant);
|
||||
}
|
||||
}
|
||||
final chunkedParticipants = chunk(array: participants, size: columns);
|
||||
if (localParticipant != null) {
|
||||
chunkedParticipants.last.add(localParticipant);
|
||||
participants.add(localParticipant);
|
||||
}
|
||||
|
||||
if (moveLastOfEachRowToNextRow) {
|
||||
for (var i = 0; i < chunkedParticipants.length - 1; i++) {
|
||||
var participant = chunkedParticipants[i].removeLast();
|
||||
chunkedParticipants[i + 1].insert(0, participant);
|
||||
}
|
||||
}
|
||||
|
||||
for (final participantChunk in chunkedParticipants) {
|
||||
final rowChildren = <Widget>[];
|
||||
for (final participant in participantChunk) {
|
||||
rowChildren.add(
|
||||
Container(
|
||||
width: size.width / participantChunk.length,
|
||||
height: size.height / chunkedParticipants.length,
|
||||
child: participant,
|
||||
),
|
||||
);
|
||||
}
|
||||
children.add(
|
||||
Container(
|
||||
height: size.height / chunkedParticipants.length,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: rowChildren,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
NoiseBox _buildNoiseBox() {
|
||||
return NoiseBox(
|
||||
density: NoiseBoxDensity.xLow,
|
||||
backgroundColor: Colors.grey.shade900,
|
||||
child: Center(
|
||||
child: Container(
|
||||
color: Colors.black54,
|
||||
width: double.infinity,
|
||||
height: 40,
|
||||
child: Center(
|
||||
child: Text(
|
||||
'Waiting for another participant to connect to the call...',
|
||||
key: Key('text-wait'),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<List<T>> chunk<T>({@required List<T> array, @required int size}) {
|
||||
final result = <List<T>>[];
|
||||
if (array.isEmpty || size <= 0) {
|
||||
return result;
|
||||
}
|
||||
var first = 0;
|
||||
var last = size;
|
||||
final totalLoop = array.length % size == 0 ? array.length ~/ size : array.length ~/ size + 1;
|
||||
for (var i = 0; i < totalLoop; i++) {
|
||||
if (last > array.length) {
|
||||
result.add(array.sublist(first, array.length));
|
||||
} else {
|
||||
result.add(array.sublist(first, last));
|
||||
}
|
||||
first = last;
|
||||
last = last + size;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void _onHeightBar(double height) {
|
||||
_onButtonBarHeightStreamController.add(height);
|
||||
}
|
||||
|
||||
void _onShowBar() {
|
||||
setState(() {
|
||||
SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom, SystemUiOverlay.top]);
|
||||
});
|
||||
_onButtonBarVisibleStreamController.add(true);
|
||||
}
|
||||
|
||||
void _onHideBar() {
|
||||
setState(() {
|
||||
SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
|
||||
});
|
||||
_onButtonBarVisibleStreamController.add(false);
|
||||
}
|
||||
|
||||
Future<void> _wakeLock(bool enable) async {
|
||||
try {
|
||||
return await (enable ? Wakelock.enable() : Wakelock.disable());
|
||||
} catch (err) {
|
||||
print('Unable to change the Wakelock and set it to $enable');
|
||||
print(err);
|
||||
}
|
||||
}
|
||||
|
||||
void _conferenceRoomUpdated() {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
// import 'dart:async';
|
||||
//
|
||||
// import 'package:diplomaticquarterapp/models/LiveCare/room_model.dart';
|
||||
// import 'package:diplomaticquarterapp/pages/conference/conference_button_bar.dart';
|
||||
// import 'package:diplomaticquarterapp/pages/conference/conference_room.dart';
|
||||
// import 'package:diplomaticquarterapp/pages/landing/landing_page.dart';
|
||||
// import 'package:diplomaticquarterapp/pages/conference/draggable_publisher.dart';
|
||||
// import 'package:diplomaticquarterapp/pages/conference/participant_widget.dart';
|
||||
// import 'package:diplomaticquarterapp/pages/conference/widgets/noise_box.dart';
|
||||
// import 'package:diplomaticquarterapp/pages/conference/widgets/platform_alert_dialog.dart';
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:flutter/services.dart';
|
||||
// import 'package:wakelock/wakelock.dart';
|
||||
//
|
||||
// class ConferencePage extends StatefulWidget {
|
||||
// final RoomModel roomModel;
|
||||
//
|
||||
// const ConferencePage({Key key, this.roomModel}) : super(key: key);
|
||||
//
|
||||
// @override
|
||||
// _ConferencePageState createState() => _ConferencePageState();
|
||||
// }
|
||||
//
|
||||
// class _ConferencePageState extends State<ConferencePage> {
|
||||
// final StreamController<bool> _onButtonBarVisibleStreamController = StreamController<bool>.broadcast();
|
||||
// final StreamController<double> _onButtonBarHeightStreamController = StreamController<double>.broadcast();
|
||||
// // ConferenceRoom _conferenceRoom;
|
||||
// StreamSubscription _onConferenceRoomException;
|
||||
//
|
||||
// @override
|
||||
// void initState() {
|
||||
// super.initState();
|
||||
// _lockInPortrait();
|
||||
// _connectToRoom();
|
||||
// _wakeLock(true);
|
||||
// }
|
||||
//
|
||||
// void _connectToRoom() async {
|
||||
// try {
|
||||
// final conferenceRoom = ConferenceRoom(
|
||||
// name: widget.roomModel.name,
|
||||
// token: widget.roomModel.token,
|
||||
// identity: widget.roomModel.identity,
|
||||
// );
|
||||
// await conferenceRoom.connect();
|
||||
// setState(() {
|
||||
// _conferenceRoom = conferenceRoom;
|
||||
// _onConferenceRoomException = _conferenceRoom.onException.listen((err) async {
|
||||
// await PlatformAlertDialog(
|
||||
// title: err is PlatformException ? err.message : 'An error occured',
|
||||
// content: err is PlatformException ? err.details : err.toString(),
|
||||
// defaultActionText: 'OK',
|
||||
// ).show(context);
|
||||
// });
|
||||
// _conferenceRoom.addListener(_conferenceRoomUpdated);
|
||||
// });
|
||||
// } catch (err) {
|
||||
// print(err);
|
||||
// await PlatformAlertDialog(
|
||||
// title: err is PlatformException ? err.message : 'An error occured',
|
||||
// content: err is PlatformException ? err.details : err.toString(),
|
||||
// defaultActionText: 'OK',
|
||||
// ).show(context);
|
||||
//
|
||||
// Navigator.of(context).pop();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Future<void> _lockInPortrait() async {
|
||||
// await SystemChrome.setPreferredOrientations(<DeviceOrientation>[
|
||||
// DeviceOrientation.portraitUp,
|
||||
// DeviceOrientation.portraitDown,
|
||||
// ]);
|
||||
// }
|
||||
//
|
||||
// @override
|
||||
// void dispose() {
|
||||
// _freePortraitLock();
|
||||
// _wakeLock(false);
|
||||
// _disposeStreamsAndSubscriptions();
|
||||
// if (_conferenceRoom != null) _conferenceRoom.removeListener(_conferenceRoomUpdated);
|
||||
// super.dispose();
|
||||
// }
|
||||
//
|
||||
// Future<void> _freePortraitLock() async {
|
||||
// await SystemChrome.setPreferredOrientations(<DeviceOrientation>[
|
||||
// DeviceOrientation.landscapeRight,
|
||||
// DeviceOrientation.landscapeLeft,
|
||||
// DeviceOrientation.portraitUp,
|
||||
// DeviceOrientation.portraitDown,
|
||||
// ]);
|
||||
// }
|
||||
//
|
||||
// Future<void> _disposeStreamsAndSubscriptions() async {
|
||||
// if (_onButtonBarVisibleStreamController != null) await _onButtonBarVisibleStreamController.close();
|
||||
// if (_onButtonBarHeightStreamController != null) await _onButtonBarHeightStreamController.close();
|
||||
// if (_onConferenceRoomException != null) await _onConferenceRoomException.cancel();
|
||||
// }
|
||||
//
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return WillPopScope(
|
||||
// onWillPop: () async => false,
|
||||
// child: Scaffold(
|
||||
// backgroundColor: Colors.white,
|
||||
// body: _conferenceRoom == null ? showProgress() : buildLayout(),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// LayoutBuilder buildLayout() {
|
||||
// return LayoutBuilder(
|
||||
// builder: (BuildContext context, BoxConstraints constraints) {
|
||||
// return Stack(
|
||||
// children: <Widget>[
|
||||
// _buildParticipants(context, constraints.biggest, _conferenceRoom),
|
||||
// ConferenceButtonBar(
|
||||
// audioEnabled: _conferenceRoom.onAudioEnabled,
|
||||
// videoEnabled: _conferenceRoom.onVideoEnabled,
|
||||
// onAudioEnabled: _conferenceRoom.toggleAudioEnabled,
|
||||
// onVideoEnabled: _conferenceRoom.toggleVideoEnabled,
|
||||
// onHangup: _onHangup,
|
||||
// onSwitchCamera: _conferenceRoom.switchCamera,
|
||||
// onPersonAdd: _onPersonAdd,
|
||||
// onPersonRemove: _onPersonRemove,
|
||||
// onHeight: _onHeightBar,
|
||||
// onShow: _onShowBar,
|
||||
// onHide: _onHideBar,
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// Widget showProgress() {
|
||||
// return Column(
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
// crossAxisAlignment: CrossAxisAlignment.center,
|
||||
// children: <Widget>[
|
||||
// Center(child: CircularProgressIndicator()),
|
||||
// SizedBox(
|
||||
// height: 10,
|
||||
// ),
|
||||
// Text(
|
||||
// 'Connecting to the call...',
|
||||
// style: TextStyle(color: Colors.white),
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// Future<void> _onHangup() async {
|
||||
// print('onHangup');
|
||||
// await _conferenceRoom.disconnect();
|
||||
// LandingPage.isOpenCallPage = false;
|
||||
// Navigator.of(context).pop();
|
||||
// }
|
||||
//
|
||||
// void _onPersonAdd() {
|
||||
// print('onPersonAdd');
|
||||
// try {
|
||||
// _conferenceRoom.addDummy(
|
||||
// child: Stack(
|
||||
// children: <Widget>[
|
||||
// const Placeholder(),
|
||||
// Center(
|
||||
// child: Text(
|
||||
// (_conferenceRoom.participants.length + 1).toString(),
|
||||
// style: const TextStyle(
|
||||
// shadows: <Shadow>[
|
||||
// Shadow(
|
||||
// blurRadius: 3.0,
|
||||
// color: Color.fromARGB(255, 0, 0, 0),
|
||||
// ),
|
||||
// Shadow(
|
||||
// blurRadius: 8.0,
|
||||
// color: Color.fromARGB(255, 255, 255, 255),
|
||||
// ),
|
||||
// ],
|
||||
// fontSize: 80,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// } on PlatformException catch (err) {
|
||||
// PlatformAlertDialog(
|
||||
// title: err.message,
|
||||
// content: err.details,
|
||||
// defaultActionText: 'OK',
|
||||
// ).show(context);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// void _onPersonRemove() {
|
||||
// print('onPersonRemove');
|
||||
// _conferenceRoom.removeDummy();
|
||||
// }
|
||||
//
|
||||
// Widget _buildParticipants(BuildContext context, Size size, ConferenceRoom conferenceRoom) {
|
||||
// final children = <Widget>[];
|
||||
// final length = conferenceRoom.participants.length;
|
||||
//
|
||||
// if (length <= 2) {
|
||||
// _buildOverlayLayout(context, size, children);
|
||||
// return Stack(children: children);
|
||||
// }
|
||||
//
|
||||
// void buildInCols(bool removeLocalBeforeChunking, bool moveLastOfEachRowToNextRow, int columns) {
|
||||
// _buildLayoutInGrid(
|
||||
// context,
|
||||
// size,
|
||||
// children,
|
||||
// removeLocalBeforeChunking: removeLocalBeforeChunking,
|
||||
// moveLastOfEachRowToNextRow: moveLastOfEachRowToNextRow,
|
||||
// columns: columns,
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// // if (length <= 3) {
|
||||
// // buildInCols(true, false, 1);
|
||||
// // } else if (length == 5) {
|
||||
// // buildInCols(false, true, 2);
|
||||
// // } else if (length <= 6 || length == 8) {
|
||||
// // buildInCols(false, false, 2);
|
||||
// // } else if (length == 7 || length == 9) {
|
||||
// // buildInCols(true, false, 2);
|
||||
// // } else if (length == 10) {
|
||||
// // buildInCols(false, true, 3);
|
||||
// // } else if (length == 13 || length == 16) {
|
||||
// // buildInCols(true, false, 3);
|
||||
// // } else if (length <= 18) {
|
||||
// // buildInCols(false, false, 3);
|
||||
// // }
|
||||
//
|
||||
// return Column(
|
||||
// children: children,
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// void _buildOverlayLayout(BuildContext context, Size size, List<Widget> children) {
|
||||
// final participants = _conferenceRoom.participants;
|
||||
// if (participants.length == 1) {
|
||||
// children.add(_buildNoiseBox());
|
||||
// } else {
|
||||
// final remoteParticipant = participants.firstWhere((ParticipantWidget participant) => participant.isRemote, orElse: () => null);
|
||||
// if (remoteParticipant != null) {
|
||||
// children.add(remoteParticipant);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// final localParticipant = participants.firstWhere((ParticipantWidget participant) => !participant.isRemote, orElse: () => null);
|
||||
// if (localParticipant != null) {
|
||||
// children.add(DraggablePublisher(
|
||||
// key: Key('publisher'),
|
||||
// child: localParticipant,
|
||||
// availableScreenSize: size,
|
||||
// onButtonBarVisible: _onButtonBarVisibleStreamController.stream,
|
||||
// onButtonBarHeight: _onButtonBarHeightStreamController.stream,
|
||||
// ));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// void _buildLayoutInGrid(
|
||||
// BuildContext context,
|
||||
// Size size,
|
||||
// List<Widget> children, {
|
||||
// bool removeLocalBeforeChunking = false,
|
||||
// bool moveLastOfEachRowToNextRow = false,
|
||||
// int columns = 2,
|
||||
// }) {
|
||||
// final participants = _conferenceRoom.participants;
|
||||
// ParticipantWidget localParticipant;
|
||||
// if (removeLocalBeforeChunking) {
|
||||
// localParticipant = participants.firstWhere((ParticipantWidget participant) => !participant.isRemote, orElse: () => null);
|
||||
// if (localParticipant != null) {
|
||||
// participants.remove(localParticipant);
|
||||
// }
|
||||
// }
|
||||
// final chunkedParticipants = chunk(array: participants, size: columns);
|
||||
// if (localParticipant != null) {
|
||||
// chunkedParticipants.last.add(localParticipant);
|
||||
// participants.add(localParticipant);
|
||||
// }
|
||||
//
|
||||
// if (moveLastOfEachRowToNextRow) {
|
||||
// for (var i = 0; i < chunkedParticipants.length - 1; i++) {
|
||||
// var participant = chunkedParticipants[i].removeLast();
|
||||
// chunkedParticipants[i + 1].insert(0, participant);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for (final participantChunk in chunkedParticipants) {
|
||||
// final rowChildren = <Widget>[];
|
||||
// for (final participant in participantChunk) {
|
||||
// rowChildren.add(
|
||||
// Container(
|
||||
// width: size.width / participantChunk.length,
|
||||
// height: size.height / chunkedParticipants.length,
|
||||
// child: participant,
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// children.add(
|
||||
// Container(
|
||||
// height: size.height / chunkedParticipants.length,
|
||||
// child: Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
// children: rowChildren,
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// NoiseBox _buildNoiseBox() {
|
||||
// return NoiseBox(
|
||||
// density: NoiseBoxDensity.xLow,
|
||||
// backgroundColor: Colors.grey.shade900,
|
||||
// child: Center(
|
||||
// child: Container(
|
||||
// color: Colors.black54,
|
||||
// width: double.infinity,
|
||||
// height: 40,
|
||||
// child: Center(
|
||||
// child: Text(
|
||||
// 'Waiting for another participant to connect to the call...',
|
||||
// key: Key('text-wait'),
|
||||
// textAlign: TextAlign.center,
|
||||
// style: TextStyle(color: Colors.white),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// List<List<T>> chunk<T>({@required List<T> array, @required int size}) {
|
||||
// final result = <List<T>>[];
|
||||
// if (array.isEmpty || size <= 0) {
|
||||
// return result;
|
||||
// }
|
||||
// var first = 0;
|
||||
// var last = size;
|
||||
// final totalLoop = array.length % size == 0 ? array.length ~/ size : array.length ~/ size + 1;
|
||||
// for (var i = 0; i < totalLoop; i++) {
|
||||
// if (last > array.length) {
|
||||
// result.add(array.sublist(first, array.length));
|
||||
// } else {
|
||||
// result.add(array.sublist(first, last));
|
||||
// }
|
||||
// first = last;
|
||||
// last = last + size;
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// void _onHeightBar(double height) {
|
||||
// _onButtonBarHeightStreamController.add(height);
|
||||
// }
|
||||
//
|
||||
// void _onShowBar() {
|
||||
// setState(() {
|
||||
// SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom, SystemUiOverlay.top]);
|
||||
// });
|
||||
// _onButtonBarVisibleStreamController.add(true);
|
||||
// }
|
||||
//
|
||||
// void _onHideBar() {
|
||||
// setState(() {
|
||||
// SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
|
||||
// });
|
||||
// _onButtonBarVisibleStreamController.add(false);
|
||||
// }
|
||||
//
|
||||
// Future<void> _wakeLock(bool enable) async {
|
||||
// try {
|
||||
// return await (enable ? Wakelock.enable() : Wakelock.disable());
|
||||
// } catch (err) {
|
||||
// print('Unable to change the Wakelock and set it to $enable');
|
||||
// print(err);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// void _conferenceRoomUpdated() {
|
||||
// setState(() {});
|
||||
// }
|
||||
// }
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,341 +1,341 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:async/async.dart';
|
||||
import 'package:diplomaticquarterapp/config/config.dart';
|
||||
import 'package:diplomaticquarterapp/core/model/pharmacies/order_detail.dart';
|
||||
import 'package:diplomaticquarterapp/core/service/parmacyModule/order-preview-service.dart';
|
||||
import 'package:diplomaticquarterapp/locator.dart';
|
||||
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
|
||||
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
||||
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_animarker/lat_lng_interpolation.dart';
|
||||
import 'package:flutter_animarker/models/lat_lng_delta.dart';
|
||||
import 'package:flutter_animarker/models/lat_lng_info.dart';
|
||||
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:location/location.dart';
|
||||
|
||||
class TrackDriver extends StatefulWidget {
|
||||
final OrderDetailModel order;
|
||||
TrackDriver({this.order});
|
||||
|
||||
@override
|
||||
State<TrackDriver> createState() => _TrackDriverState();
|
||||
}
|
||||
|
||||
class _TrackDriverState extends State<TrackDriver> {
|
||||
OrderPreviewService _orderServices = locator<OrderPreviewService>();
|
||||
OrderDetailModel _order;
|
||||
|
||||
Completer<GoogleMapController> _controller = Completer();
|
||||
|
||||
|
||||
double CAMERA_ZOOM = 14;
|
||||
double CAMERA_TILT = 0;
|
||||
double CAMERA_BEARING = 30;
|
||||
LatLng SOURCE_LOCATION = null;
|
||||
LatLng DEST_LOCATION = null;
|
||||
|
||||
// for my drawn routes on the map
|
||||
Set<Polyline> _polylines = Set<Polyline>();
|
||||
List<LatLng> polylineCoordinates = [];
|
||||
PolylinePoints polylinePoints;
|
||||
|
||||
Set<Marker> _markers = Set<Marker>();
|
||||
|
||||
BitmapDescriptor sourceIcon; // for my custom marker pins
|
||||
BitmapDescriptor destinationIcon; // for my custom marker pins
|
||||
Location location;// wrapper around the location API
|
||||
|
||||
|
||||
int locationUpdateFreq = 2;
|
||||
LatLngInterpolationStream _latLngStream;
|
||||
StreamGroup<LatLngDelta> subscriptions;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_order = widget.order;
|
||||
DEST_LOCATION = _order.shippingAddress.getLocation();
|
||||
location = new Location();
|
||||
polylinePoints = PolylinePoints();
|
||||
setSourceAndDestinationIcons();
|
||||
|
||||
initMarkerUpdateStream();
|
||||
startUpdatingDriverLocation();
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
subscriptions.close();
|
||||
_latLngStream.cancel();
|
||||
stopUpdatingDriverLocation();
|
||||
}
|
||||
|
||||
initMarkerUpdateStream(){
|
||||
_latLngStream = LatLngInterpolationStream(movementDuration: Duration(seconds: locationUpdateFreq+1));
|
||||
subscriptions = StreamGroup<LatLngDelta>();
|
||||
|
||||
subscriptions.add(_latLngStream.getAnimatedPosition('sourcePin'));
|
||||
subscriptions.stream.listen((LatLngDelta delta) {
|
||||
//Update the marker with animation
|
||||
setState(() {
|
||||
//Get the marker Id for this animation
|
||||
var markerId = MarkerId(delta.markerId);
|
||||
Marker sourceMarker = Marker(
|
||||
markerId: markerId,
|
||||
// rotation: delta.rotation,
|
||||
icon: sourceIcon,
|
||||
position: LatLng(
|
||||
delta.from.latitude,
|
||||
delta.from.longitude,
|
||||
),
|
||||
onTap: onSourceMarkerTap
|
||||
);
|
||||
|
||||
_markers.removeWhere((m) => m.markerId.value == 'sourcePin');
|
||||
_markers.add(sourceMarker);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return AppScaffold(
|
||||
appBarTitle: TranslationBase.of(context).deliveryDriverTrack,
|
||||
isShowAppBar: true,
|
||||
isPharmacy: true,
|
||||
showPharmacyCart: false,
|
||||
showHomeAppBarIcon: false,
|
||||
body: GoogleMap(
|
||||
myLocationEnabled: true,
|
||||
compassEnabled: true,
|
||||
markers: _markers,
|
||||
polylines: _polylines,
|
||||
mapType: MapType.normal,
|
||||
initialCameraPosition: CameraPosition(target: DEST_LOCATION, zoom: 4),
|
||||
onMapCreated: (GoogleMapController controller) {
|
||||
_controller.complete(controller);
|
||||
// showPinsOnMap();
|
||||
},
|
||||
),
|
||||
// floatingActionButton: FloatingActionButton.extended(
|
||||
// onPressed: _goToDriver,
|
||||
// label: Text('To the lake!'),
|
||||
// icon: Icon(Icons.directions_boat),
|
||||
// ),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void setSourceAndDestinationIcons() async {
|
||||
final Uint8List srcMarkerBytes = await getBytesFromAsset('assets/images/map_markers/source_map_marker.png', getMarkerIconSize());
|
||||
final Uint8List destMarkerBytes = await getBytesFromAsset('assets/images/map_markers/destination_map_marker.png', getMarkerIconSize());
|
||||
sourceIcon = await BitmapDescriptor.fromBytes(srcMarkerBytes);
|
||||
destinationIcon = await BitmapDescriptor.fromBytes(destMarkerBytes);
|
||||
}
|
||||
|
||||
CameraPosition _orderDeliveryLocationCamera(){
|
||||
if(DEST_LOCATION != null){
|
||||
final CameraPosition orderDeliveryLocCamera = CameraPosition(
|
||||
bearing: CAMERA_BEARING,
|
||||
target: DEST_LOCATION,
|
||||
tilt: CAMERA_TILT,
|
||||
zoom: CAMERA_ZOOM);
|
||||
return orderDeliveryLocCamera;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
CameraPosition _driverLocationCamera(){
|
||||
if(DEST_LOCATION != null) {
|
||||
final CameraPosition driverLocCamera = CameraPosition(
|
||||
bearing: CAMERA_BEARING,
|
||||
target: SOURCE_LOCATION,
|
||||
tilt: CAMERA_TILT,
|
||||
zoom: CAMERA_ZOOM);
|
||||
return driverLocCamera;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Future<void> _goToOrderDeliveryLocation() async {
|
||||
final GoogleMapController controller = await _controller.future;
|
||||
final CameraPosition orderDeliveryLocCamera = _orderDeliveryLocationCamera();
|
||||
controller.animateCamera(CameraUpdate.newCameraPosition(orderDeliveryLocCamera));
|
||||
}
|
||||
|
||||
Future<void> _goToDriver() async {
|
||||
final GoogleMapController controller = await _controller.future;
|
||||
final CameraPosition driverLocCamera = _driverLocationCamera();
|
||||
controller.animateCamera(CameraUpdate.newCameraPosition(driverLocCamera));
|
||||
}
|
||||
|
||||
|
||||
void showPinsOnMap() {
|
||||
// source pin
|
||||
if(SOURCE_LOCATION != null){
|
||||
setState(() {
|
||||
var pinPosition = SOURCE_LOCATION;
|
||||
_markers.removeWhere((m) => m.markerId.value == 'sourcePin');
|
||||
_markers.add(Marker(
|
||||
markerId: MarkerId('sourcePin'),
|
||||
position: pinPosition,
|
||||
icon: sourceIcon,
|
||||
infoWindow: InfoWindow(title: TranslationBase.of(context).driver),
|
||||
onTap: onSourceMarkerTap
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
// destination pin
|
||||
if(DEST_LOCATION != null){
|
||||
setState(() {
|
||||
var destPosition = DEST_LOCATION;
|
||||
_markers.removeWhere((m) => m.markerId.value == 'destPin');
|
||||
_markers.add(Marker(
|
||||
markerId: MarkerId('destPin'),
|
||||
position: destPosition,
|
||||
icon: destinationIcon,
|
||||
infoWindow: InfoWindow(title: TranslationBase.of(context).deliveryLocation),
|
||||
onTap: onDestinationMarkerTap
|
||||
));
|
||||
});
|
||||
}
|
||||
// set the route lines on the map from source to destination
|
||||
// for more info follow this tutorial
|
||||
// drawRoute();
|
||||
}
|
||||
|
||||
void updatePinOnMap() async {
|
||||
_latLngStream.addLatLng(LatLngInfo(SOURCE_LOCATION.latitude, SOURCE_LOCATION.longitude, "sourcePin"));
|
||||
drawRoute();
|
||||
}
|
||||
|
||||
void drawRoute() async {
|
||||
return; // Ignore draw Route
|
||||
|
||||
List<PointLatLng> result = await polylinePoints.getRouteBetweenCoordinates(
|
||||
GOOGLE_API_KEY,
|
||||
SOURCE_LOCATION.latitude,
|
||||
SOURCE_LOCATION.longitude,
|
||||
DEST_LOCATION.latitude,
|
||||
DEST_LOCATION.longitude);
|
||||
if(result.isNotEmpty){
|
||||
result.forEach((PointLatLng point){
|
||||
polylineCoordinates.add(
|
||||
LatLng(point.latitude,point.longitude)
|
||||
);
|
||||
});
|
||||
setState(() {
|
||||
_polylines.add(Polyline(
|
||||
width: 5, // set the width of the polylines
|
||||
polylineId: PolylineId('poly'),
|
||||
color: Color.fromARGB(255, 40, 122, 198),
|
||||
points: polylineCoordinates
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
bool isLocationUpdating = false;
|
||||
startUpdatingDriverLocation({int frequencyInSeconds = 2}) async{
|
||||
isLocationUpdating = true;
|
||||
int driverId = int.tryParse(_order.driverID);
|
||||
|
||||
Future.doWhile(() async{
|
||||
if(isLocationUpdating){
|
||||
|
||||
await Future.delayed(Duration(seconds: frequencyInSeconds));
|
||||
|
||||
showLoading();
|
||||
LatLng driverLocation = (await _orderServices.getDriverLocation(driverId));
|
||||
hideLoading();
|
||||
|
||||
if(driverLocation != null){
|
||||
if(SOURCE_LOCATION == null || DEST_LOCATION == null){
|
||||
SOURCE_LOCATION = driverLocation;
|
||||
DEST_LOCATION = _order.shippingAddress.getLocation();
|
||||
showPinsOnMap();
|
||||
}
|
||||
SOURCE_LOCATION = driverLocation;
|
||||
updatePinOnMap();
|
||||
updateMapCamera();
|
||||
}else{
|
||||
GifLoaderDialogUtils.hideDialog(context);
|
||||
}
|
||||
}
|
||||
return isLocationUpdating;
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
showLoading(){
|
||||
if(SOURCE_LOCATION == null){
|
||||
GifLoaderDialogUtils.showMyDialog(context);
|
||||
}
|
||||
}
|
||||
|
||||
hideLoading(){
|
||||
if(SOURCE_LOCATION == null){
|
||||
GifLoaderDialogUtils.hideDialog(context);
|
||||
}
|
||||
}
|
||||
|
||||
stopUpdatingDriverLocation(){
|
||||
isLocationUpdating = false;
|
||||
}
|
||||
|
||||
Future<Uint8List> getBytesFromAsset(String path, int width) async {
|
||||
ByteData data = await rootBundle.load(path);
|
||||
ui.Codec codec = await ui.instantiateImageCodec(data.buffer.asUint8List(), targetWidth: width);
|
||||
ui.FrameInfo fi = await codec.getNextFrame();
|
||||
return (await fi.image.toByteData(format: ui.ImageByteFormat.png)).buffer.asUint8List();
|
||||
}
|
||||
|
||||
int getMarkerIconSize(){
|
||||
return 140;
|
||||
}
|
||||
|
||||
updateMapCamera() async{
|
||||
if(SOURCE_LOCATION != null && DEST_LOCATION != null){
|
||||
|
||||
// 'package:google_maps_flutter_platform_interface/src/types/location.dart': Failed assertion: line 72 pos 16: 'southwest.latitude <= northeast.latitude': is not true.
|
||||
LatLngBounds bound;
|
||||
if(SOURCE_LOCATION.latitude <= DEST_LOCATION.latitude){
|
||||
bound = LatLngBounds(southwest: SOURCE_LOCATION, northeast: DEST_LOCATION);
|
||||
}else{
|
||||
bound = LatLngBounds(southwest: DEST_LOCATION, northeast: SOURCE_LOCATION);
|
||||
}
|
||||
|
||||
if(bound == null)
|
||||
return;
|
||||
|
||||
CameraUpdate camera = CameraUpdate.newLatLngBounds(bound, 50);
|
||||
final GoogleMapController controller = await _controller.future;
|
||||
controller.animateCamera(camera);
|
||||
}
|
||||
}
|
||||
|
||||
bool showSrcMarkerTitle = false;
|
||||
onSourceMarkerTap() async{
|
||||
// showSrcMarkerTitle = !showSrcMarkerTitle;
|
||||
}
|
||||
|
||||
bool showDestMarkerTitle = false;
|
||||
onDestinationMarkerTap() async{
|
||||
// showDestMarkerTitle = !showDestMarkerTitle;
|
||||
// Marker m = _markers.firstWhere((m) => m.markerId.value == 'destPin');
|
||||
// if(showDestMarkerTitle){
|
||||
// }
|
||||
}
|
||||
}
|
||||
// import 'dart:async';
|
||||
// import 'dart:typed_data';
|
||||
// import 'dart:ui' as ui;
|
||||
//
|
||||
// import 'package:async/async.dart';
|
||||
// import 'package:diplomaticquarterapp/config/config.dart';
|
||||
// import 'package:diplomaticquarterapp/core/model/pharmacies/order_detail.dart';
|
||||
// import 'package:diplomaticquarterapp/core/service/parmacyModule/order-preview-service.dart';
|
||||
// import 'package:diplomaticquarterapp/locator.dart';
|
||||
// import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
|
||||
// import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
||||
// import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:flutter/services.dart';
|
||||
// import 'package:flutter_animarker/lat_lng_interpolation.dart';
|
||||
// import 'package:flutter_animarker/models/lat_lng_delta.dart';
|
||||
// import 'package:flutter_animarker/models/lat_lng_info.dart';
|
||||
// import 'package:flutter_polyline_points/flutter_polyline_points.dart';
|
||||
// import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
// import 'package:location/location.dart';
|
||||
//
|
||||
// class TrackDriver extends StatefulWidget {
|
||||
// final OrderDetailModel order;
|
||||
// TrackDriver({this.order});
|
||||
//
|
||||
// @override
|
||||
// State<TrackDriver> createState() => _TrackDriverState();
|
||||
// }
|
||||
//
|
||||
// class _TrackDriverState extends State<TrackDriver> {
|
||||
// OrderPreviewService _orderServices = locator<OrderPreviewService>();
|
||||
// OrderDetailModel _order;
|
||||
//
|
||||
// Completer<GoogleMapController> _controller = Completer();
|
||||
//
|
||||
//
|
||||
// double CAMERA_ZOOM = 14;
|
||||
// double CAMERA_TILT = 0;
|
||||
// double CAMERA_BEARING = 30;
|
||||
// LatLng SOURCE_LOCATION = null;
|
||||
// LatLng DEST_LOCATION = null;
|
||||
//
|
||||
// // for my drawn routes on the map
|
||||
// Set<Polyline> _polylines = Set<Polyline>();
|
||||
// List<LatLng> polylineCoordinates = [];
|
||||
// PolylinePoints polylinePoints;
|
||||
//
|
||||
// Set<Marker> _markers = Set<Marker>();
|
||||
//
|
||||
// BitmapDescriptor sourceIcon; // for my custom marker pins
|
||||
// BitmapDescriptor destinationIcon; // for my custom marker pins
|
||||
// Location location;// wrapper around the location API
|
||||
//
|
||||
//
|
||||
// int locationUpdateFreq = 2;
|
||||
// LatLngInterpolationStream _latLngStream;
|
||||
// StreamGroup<LatLngDelta> subscriptions;
|
||||
//
|
||||
// @override
|
||||
// void initState() {
|
||||
// super.initState();
|
||||
//
|
||||
// _order = widget.order;
|
||||
// DEST_LOCATION = _order.shippingAddress.getLocation();
|
||||
// location = new Location();
|
||||
// polylinePoints = PolylinePoints();
|
||||
// setSourceAndDestinationIcons();
|
||||
//
|
||||
// initMarkerUpdateStream();
|
||||
// startUpdatingDriverLocation();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @override
|
||||
// void dispose() {
|
||||
// super.dispose();
|
||||
// subscriptions.close();
|
||||
// _latLngStream.cancel();
|
||||
// stopUpdatingDriverLocation();
|
||||
// }
|
||||
//
|
||||
// initMarkerUpdateStream(){
|
||||
// _latLngStream = LatLngInterpolationStream(movementDuration: Duration(seconds: locationUpdateFreq+1));
|
||||
// subscriptions = StreamGroup<LatLngDelta>();
|
||||
//
|
||||
// subscriptions.add(_latLngStream.getAnimatedPosition('sourcePin'));
|
||||
// subscriptions.stream.listen((LatLngDelta delta) {
|
||||
// //Update the marker with animation
|
||||
// setState(() {
|
||||
// //Get the marker Id for this animation
|
||||
// var markerId = MarkerId(delta.markerId);
|
||||
// Marker sourceMarker = Marker(
|
||||
// markerId: markerId,
|
||||
// // rotation: delta.rotation,
|
||||
// icon: sourceIcon,
|
||||
// position: LatLng(
|
||||
// delta.from.latitude,
|
||||
// delta.from.longitude,
|
||||
// ),
|
||||
// onTap: onSourceMarkerTap
|
||||
// );
|
||||
//
|
||||
// _markers.removeWhere((m) => m.markerId.value == 'sourcePin');
|
||||
// _markers.add(sourceMarker);
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
//
|
||||
// return AppScaffold(
|
||||
// appBarTitle: TranslationBase.of(context).deliveryDriverTrack,
|
||||
// isShowAppBar: true,
|
||||
// isPharmacy: true,
|
||||
// showPharmacyCart: false,
|
||||
// showHomeAppBarIcon: false,
|
||||
// body: GoogleMap(
|
||||
// myLocationEnabled: true,
|
||||
// compassEnabled: true,
|
||||
// markers: _markers,
|
||||
// polylines: _polylines,
|
||||
// mapType: MapType.normal,
|
||||
// initialCameraPosition: CameraPosition(target: DEST_LOCATION, zoom: 4),
|
||||
// onMapCreated: (GoogleMapController controller) {
|
||||
// _controller.complete(controller);
|
||||
// // showPinsOnMap();
|
||||
// },
|
||||
// ),
|
||||
// // floatingActionButton: FloatingActionButton.extended(
|
||||
// // onPressed: _goToDriver,
|
||||
// // label: Text('To the lake!'),
|
||||
// // icon: Icon(Icons.directions_boat),
|
||||
// // ),
|
||||
// );
|
||||
// }
|
||||
//
|
||||
//
|
||||
// void setSourceAndDestinationIcons() async {
|
||||
// final Uint8List srcMarkerBytes = await getBytesFromAsset('assets/images/map_markers/source_map_marker.png', getMarkerIconSize());
|
||||
// final Uint8List destMarkerBytes = await getBytesFromAsset('assets/images/map_markers/destination_map_marker.png', getMarkerIconSize());
|
||||
// sourceIcon = await BitmapDescriptor.fromBytes(srcMarkerBytes);
|
||||
// destinationIcon = await BitmapDescriptor.fromBytes(destMarkerBytes);
|
||||
// }
|
||||
//
|
||||
// CameraPosition _orderDeliveryLocationCamera(){
|
||||
// if(DEST_LOCATION != null){
|
||||
// final CameraPosition orderDeliveryLocCamera = CameraPosition(
|
||||
// bearing: CAMERA_BEARING,
|
||||
// target: DEST_LOCATION,
|
||||
// tilt: CAMERA_TILT,
|
||||
// zoom: CAMERA_ZOOM);
|
||||
// return orderDeliveryLocCamera;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// CameraPosition _driverLocationCamera(){
|
||||
// if(DEST_LOCATION != null) {
|
||||
// final CameraPosition driverLocCamera = CameraPosition(
|
||||
// bearing: CAMERA_BEARING,
|
||||
// target: SOURCE_LOCATION,
|
||||
// tilt: CAMERA_TILT,
|
||||
// zoom: CAMERA_ZOOM);
|
||||
// return driverLocCamera;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// Future<void> _goToOrderDeliveryLocation() async {
|
||||
// final GoogleMapController controller = await _controller.future;
|
||||
// final CameraPosition orderDeliveryLocCamera = _orderDeliveryLocationCamera();
|
||||
// controller.animateCamera(CameraUpdate.newCameraPosition(orderDeliveryLocCamera));
|
||||
// }
|
||||
//
|
||||
// Future<void> _goToDriver() async {
|
||||
// final GoogleMapController controller = await _controller.future;
|
||||
// final CameraPosition driverLocCamera = _driverLocationCamera();
|
||||
// controller.animateCamera(CameraUpdate.newCameraPosition(driverLocCamera));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// void showPinsOnMap() {
|
||||
// // source pin
|
||||
// if(SOURCE_LOCATION != null){
|
||||
// setState(() {
|
||||
// var pinPosition = SOURCE_LOCATION;
|
||||
// _markers.removeWhere((m) => m.markerId.value == 'sourcePin');
|
||||
// _markers.add(Marker(
|
||||
// markerId: MarkerId('sourcePin'),
|
||||
// position: pinPosition,
|
||||
// icon: sourceIcon,
|
||||
// infoWindow: InfoWindow(title: TranslationBase.of(context).driver),
|
||||
// onTap: onSourceMarkerTap
|
||||
// ));
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// // destination pin
|
||||
// if(DEST_LOCATION != null){
|
||||
// setState(() {
|
||||
// var destPosition = DEST_LOCATION;
|
||||
// _markers.removeWhere((m) => m.markerId.value == 'destPin');
|
||||
// _markers.add(Marker(
|
||||
// markerId: MarkerId('destPin'),
|
||||
// position: destPosition,
|
||||
// icon: destinationIcon,
|
||||
// infoWindow: InfoWindow(title: TranslationBase.of(context).deliveryLocation),
|
||||
// onTap: onDestinationMarkerTap
|
||||
// ));
|
||||
// });
|
||||
// }
|
||||
// // set the route lines on the map from source to destination
|
||||
// // for more info follow this tutorial
|
||||
// // drawRoute();
|
||||
// }
|
||||
//
|
||||
// void updatePinOnMap() async {
|
||||
// _latLngStream.addLatLng(LatLngInfo(SOURCE_LOCATION.latitude, SOURCE_LOCATION.longitude, "sourcePin"));
|
||||
// drawRoute();
|
||||
// }
|
||||
//
|
||||
// void drawRoute() async {
|
||||
// return; // Ignore draw Route
|
||||
//
|
||||
// List<PointLatLng> result = await polylinePoints.getRouteBetweenCoordinates(
|
||||
// GOOGLE_API_KEY,
|
||||
// SOURCE_LOCATION.latitude,
|
||||
// SOURCE_LOCATION.longitude,
|
||||
// DEST_LOCATION.latitude,
|
||||
// DEST_LOCATION.longitude);
|
||||
// if(result.isNotEmpty){
|
||||
// result.forEach((PointLatLng point){
|
||||
// polylineCoordinates.add(
|
||||
// LatLng(point.latitude,point.longitude)
|
||||
// );
|
||||
// });
|
||||
// setState(() {
|
||||
// _polylines.add(Polyline(
|
||||
// width: 5, // set the width of the polylines
|
||||
// polylineId: PolylineId('poly'),
|
||||
// color: Color.fromARGB(255, 40, 122, 198),
|
||||
// points: polylineCoordinates
|
||||
// ));
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// bool isLocationUpdating = false;
|
||||
// startUpdatingDriverLocation({int frequencyInSeconds = 2}) async{
|
||||
// isLocationUpdating = true;
|
||||
// int driverId = int.tryParse(_order.driverID);
|
||||
//
|
||||
// Future.doWhile(() async{
|
||||
// if(isLocationUpdating){
|
||||
//
|
||||
// await Future.delayed(Duration(seconds: frequencyInSeconds));
|
||||
//
|
||||
// showLoading();
|
||||
// LatLng driverLocation = (await _orderServices.getDriverLocation(driverId));
|
||||
// hideLoading();
|
||||
//
|
||||
// if(driverLocation != null){
|
||||
// if(SOURCE_LOCATION == null || DEST_LOCATION == null){
|
||||
// SOURCE_LOCATION = driverLocation;
|
||||
// DEST_LOCATION = _order.shippingAddress.getLocation();
|
||||
// showPinsOnMap();
|
||||
// }
|
||||
// SOURCE_LOCATION = driverLocation;
|
||||
// updatePinOnMap();
|
||||
// updateMapCamera();
|
||||
// }else{
|
||||
// GifLoaderDialogUtils.hideDialog(context);
|
||||
// }
|
||||
// }
|
||||
// return isLocationUpdating;
|
||||
//
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// showLoading(){
|
||||
// if(SOURCE_LOCATION == null){
|
||||
// GifLoaderDialogUtils.showMyDialog(context);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// hideLoading(){
|
||||
// if(SOURCE_LOCATION == null){
|
||||
// GifLoaderDialogUtils.hideDialog(context);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// stopUpdatingDriverLocation(){
|
||||
// isLocationUpdating = false;
|
||||
// }
|
||||
//
|
||||
// Future<Uint8List> getBytesFromAsset(String path, int width) async {
|
||||
// ByteData data = await rootBundle.load(path);
|
||||
// ui.Codec codec = await ui.instantiateImageCodec(data.buffer.asUint8List(), targetWidth: width);
|
||||
// ui.FrameInfo fi = await codec.getNextFrame();
|
||||
// return (await fi.image.toByteData(format: ui.ImageByteFormat.png)).buffer.asUint8List();
|
||||
// }
|
||||
//
|
||||
// int getMarkerIconSize(){
|
||||
// return 140;
|
||||
// }
|
||||
//
|
||||
// updateMapCamera() async{
|
||||
// if(SOURCE_LOCATION != null && DEST_LOCATION != null){
|
||||
//
|
||||
// // 'package:google_maps_flutter_platform_interface/src/types/location.dart': Failed assertion: line 72 pos 16: 'southwest.latitude <= northeast.latitude': is not true.
|
||||
// LatLngBounds bound;
|
||||
// if(SOURCE_LOCATION.latitude <= DEST_LOCATION.latitude){
|
||||
// bound = LatLngBounds(southwest: SOURCE_LOCATION, northeast: DEST_LOCATION);
|
||||
// }else{
|
||||
// bound = LatLngBounds(southwest: DEST_LOCATION, northeast: SOURCE_LOCATION);
|
||||
// }
|
||||
//
|
||||
// if(bound == null)
|
||||
// return;
|
||||
//
|
||||
// CameraUpdate camera = CameraUpdate.newLatLngBounds(bound, 50);
|
||||
// final GoogleMapController controller = await _controller.future;
|
||||
// controller.animateCamera(camera);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// bool showSrcMarkerTitle = false;
|
||||
// onSourceMarkerTap() async{
|
||||
// // showSrcMarkerTitle = !showSrcMarkerTitle;
|
||||
// }
|
||||
//
|
||||
// bool showDestMarkerTitle = false;
|
||||
// onDestinationMarkerTap() async{
|
||||
// // showDestMarkerTitle = !showDestMarkerTitle;
|
||||
// // Marker m = _markers.firstWhere((m) => m.markerId.value == 'destPin');
|
||||
// // if(showDestMarkerTitle){
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
|
||||
Loading…
Reference in New Issue