diff --git a/lib/main.dart b/lib/main.dart index 1805cb4bce6ee60225148cbf43c5a2d554d44ca0..0a1f6a161d633d2670b36d1f08ca58f2dcd19916 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -74,6 +74,7 @@ class _MyHomePageState extends State<MyHomePage> { // Set<Polyline> _polyline = {}; String _totalDuration = ''; String _totalDistance = ''; + String _totalDaysFormatted = ''; // Variables for calendar and weather filter DateTimeRange _dateRange = DateTimeRange( @@ -230,12 +231,12 @@ class _MyHomePageState extends State<MyHomePage> { var coordinates = _data['route']; int duration = _data['duration']; int distance = _data['distance']; - //TODO include day int daysAfterToday = _data['days_after_today']; - // Format duration and distance + // Format duration, distance and day _totalDuration = getTotalDuration(duration); _totalDistance = getTotalDistance(distance); + _totalDaysFormatted = getTotalDays(daysAfterToday); // Draw polyline drawPolyline(coordinates); @@ -255,6 +256,7 @@ class _MyHomePageState extends State<MyHomePage> { setState(() { _totalDuration; _totalDistance; + _totalDaysFormatted; _polyline; }); } catch (e) { @@ -285,6 +287,13 @@ class _MyHomePageState extends State<MyHomePage> { return '$distanceInKm km'; } + String getTotalDays(int daysAfterToday) { + String currentDate = convertDateFormat(DateTime.now()); + String lastDate = + convertDateFormat(DateTime.now().add(Duration(days: daysAfterToday))); + return "$currentDate - $lastDate"; + } + List<String> getForbidden() { List<String> forbidden = []; for (var option in _selectedOptions) { @@ -989,281 +998,321 @@ class _MyHomePageState extends State<MyHomePage> { return Stack( children: [ Column( - children: [ - Container( - margin: EdgeInsets.only(bottom: 15, top: 5), - decoration: BoxDecoration( - color: Color.fromRGBO(53, 56, 63, 1), - borderRadius: - BorderRadius.all(Radius.circular(25))), - padding: - EdgeInsets.only(bottom: 15, top: 15, left: 20), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - padding: EdgeInsets.only(right: 5, top: 2), - child: Icon( - Icons.calendar_month, - color: Theme.of(context).accentColor, - size: 20, - ), - ), - Text( - 'Picked Date: ', - style: TextStyle( - letterSpacing: 0.6, - fontSize: 21, - fontWeight: FontWeight.w500, - color: Theme.of(context).accentColor), - ), - Text( - displayDate(), - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.w400, - color: Theme.of(context).accentColor), - ), - ], - ), - ), - Container( - margin: EdgeInsets.only(bottom: 10), - padding: EdgeInsets.only(bottom: 15), - decoration: BoxDecoration( - color: Color.fromRGBO(53, 56, 63, 1), - borderRadius: - BorderRadius.all(Radius.circular(25))), - child: Column( - children: [ - Container( - padding: EdgeInsets.only( - bottom: 5, top: 15, left: 17), - child: Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Container( - padding: EdgeInsets.only(right: 8), - child: Icon( - WeatherIcons.cloudy, - color: Theme.of(context).accentColor, - size: 18, - ), - ), - Text( - 'Undesired Weather: ', - style: TextStyle( - letterSpacing: 0.6, - fontSize: 21, - fontWeight: FontWeight.w500, - color: - Theme.of(context).accentColor), - ), - ], - ), - ), - Row( - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - SizedBox( - width: 20, - ), - if (!_selectedOptions.isEmpty) - ...returnWidget(), - ], - ), - ], - ), - ), - Container( - padding: EdgeInsets.only(top: 7, bottom: 7), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - ElevatedButton( - onPressed: _collapse, - child: Container( - padding: EdgeInsets.only( - top: 10, - bottom: 10, - left: 135, - right: 135), - child: Text( - 'Info', - style: TextStyle(fontSize: 20), + children: [ + Container( + margin: EdgeInsets.only(bottom: 15, top: 5), + decoration: BoxDecoration( + color: Color.fromRGBO(53, 56, 63, 1), + borderRadius: + BorderRadius.all(Radius.circular(25))), + padding: EdgeInsets.only( + bottom: 15, top: 15, left: 20), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + padding: EdgeInsets.only(right: 5, top: 2), + child: Icon( + Icons.calendar_month, + color: Theme.of(context).accentColor, + size: 20, ), ), - style: ButtonStyle( - backgroundColor: MaterialStatePropertyAll( - Color.fromRGBO(13, 108, 114, 1), - ), - shape: MaterialStateProperty.all< - RoundedRectangleBorder>( - RoundedRectangleBorder( - borderRadius: BorderRadius.circular(20), - ), - ), + Text( + 'Picked Date: ', + style: TextStyle( + letterSpacing: 0.6, + fontSize: 21, + fontWeight: FontWeight.w500, + color: Theme.of(context).accentColor), ), - ), - ], + Text( + displayDate(), + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.w400, + color: Theme.of(context).accentColor), + ), + ], + ), ), - ), - if (_availableDatesForTrip != null && _isCollapsed) Container( + margin: EdgeInsets.only(bottom: 10), + padding: EdgeInsets.only(bottom: 15), decoration: BoxDecoration( color: Color.fromRGBO(53, 56, 63, 1), borderRadius: BorderRadius.all(Radius.circular(25))), - padding: EdgeInsets.only( - top: 15, left: 20, bottom: 15), - margin: EdgeInsets.only(top: 10, bottom: 10), child: Column( children: [ - Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Container( - padding: - EdgeInsets.only(right: 5, top: 2), - child: Icon( - Icons.access_time_filled_outlined, - color: Theme.of(context).accentColor, - size: 20, - ), - ), - Text( - 'Duration: ', - style: TextStyle( - letterSpacing: 0.6, - fontSize: 21, - fontWeight: FontWeight.w500, - color: - Theme.of(context).accentColor), - ), - Text( - _totalDuration, - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.w400, + Container( + padding: EdgeInsets.only( + bottom: 5, top: 15, left: 17), + child: Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Container( + padding: EdgeInsets.only(right: 8), + child: Icon( + WeatherIcons.cloudy, color: - Theme.of(context).accentColor), - ), - ], - ), - SizedBox( - height: 15, + Theme.of(context).accentColor, + size: 18, + ), + ), + Text( + 'Undesired Weather: ', + style: TextStyle( + letterSpacing: 0.6, + fontSize: 21, + fontWeight: FontWeight.w500, + color: Theme.of(context) + .accentColor), + ), + ], + ), ), Row( - crossAxisAlignment: - CrossAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.end, children: [ - Container( - padding: - EdgeInsets.only(right: 5, top: 2), - child: Icon( - Icons.directions_car_rounded, - color: Theme.of(context).accentColor, - size: 20, - ), - ), - Text( - 'Distance: ', - style: TextStyle( - letterSpacing: 0.6, - fontSize: 21, - fontWeight: FontWeight.w500, - color: - Theme.of(context).accentColor), - ), - Text( - _totalDistance, - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.w400, - color: - Theme.of(context).accentColor), + SizedBox( + width: 20, ), + if (!_selectedOptions.isEmpty) + ...returnWidget(), ], - ) + ), ], ), ), - if (_availableDatesForTrip != null && _isCollapsed) Container( - margin: EdgeInsets.only(top: 10), - padding: EdgeInsets.only(left: 5, top: 10), - decoration: BoxDecoration( - color: Color.fromRGBO(53, 56, 63, 1), - borderRadius: - BorderRadius.all(Radius.circular(25))), - child: Column( + padding: EdgeInsets.only(top: 7, bottom: 7), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, children: [ - Row(children: [ - Container( + ElevatedButton( + onPressed: _collapse, + child: Container( padding: EdgeInsets.only( - right: 3, - top: 4, - bottom: 7, - left: 15), - child: Icon( - Icons.event_available, - color: Theme.of(context).accentColor, - size: 24, + top: 10, + bottom: 10, + left: 135, + right: 135), + child: Text( + 'Info', + style: TextStyle(fontSize: 20), ), ), - Container( - padding: EdgeInsets.only( - top: 5, left: 5, bottom: 10), - child: Text( - 'Available Dates:', - style: TextStyle( - letterSpacing: 0.6, - fontSize: 21, - fontWeight: FontWeight.w500, - color: - Theme.of(context).accentColor), + style: ButtonStyle( + backgroundColor: MaterialStatePropertyAll( + Color.fromRGBO(13, 108, 114, 1), + ), + shape: MaterialStateProperty.all< + RoundedRectangleBorder>( + RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(20), + ), ), ), - ]), - for (var i = 0; - i < _availableDatesForTrip.length; - i++) - Container( - padding: const EdgeInsets.only( - top: 5, bottom: 15, left: 5), - child: Row( - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Container( - padding: EdgeInsets.only( - right: 6, left: 12), - child: Icon( - Icons.check_rounded, - color: - Theme.of(context).accentColor, - size: 20, - ), + ), + ], + ), + ), + if (_availableDatesForTrip != null && _isCollapsed) + Container( + decoration: BoxDecoration( + color: Color.fromRGBO(53, 56, 63, 1), + borderRadius: + BorderRadius.all(Radius.circular(25))), + padding: EdgeInsets.only( + top: 15, left: 20, bottom: 15), + margin: EdgeInsets.only(top: 10, bottom: 10), + child: Column( + children: [ + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Container( + padding: + EdgeInsets.only(right: 5, top: 2), + child: Icon( + Icons.access_time_filled_outlined, + color: + Theme.of(context).accentColor, + size: 20, ), - Text( - _availableDatesForTrip[i], - style: TextStyle( - letterSpacing: 0.6, - fontSize: 20, - fontWeight: FontWeight.w400, - color: Theme.of(context) - .accentColor), + ), + Text( + 'Duration: ', + style: TextStyle( + letterSpacing: 0.6, + fontSize: 21, + fontWeight: FontWeight.w500, + color: Theme.of(context) + .accentColor), + ), + Text( + _totalDuration, + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.w400, + color: Theme.of(context) + .accentColor), + ), + ], + ), + SizedBox( + height: 15, + ), + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Container( + padding: + EdgeInsets.only(right: 5, top: 2), + child: Icon( + Icons.directions_car_rounded, + color: + Theme.of(context).accentColor, + size: 20, ), - ], + ), + Text( + 'Distance: ', + style: TextStyle( + letterSpacing: 0.6, + fontSize: 21, + fontWeight: FontWeight.w500, + color: Theme.of(context) + .accentColor), + ), + Text( + _totalDistance, + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.w400, + color: Theme.of(context) + .accentColor), + ), + ], + ), + SizedBox( + height: 15, + ), + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Container( + padding: + EdgeInsets.only(right: 5, top: 2), + child: Icon( + Icons.date_range, + color: + Theme.of(context).accentColor, + size: 20, + ), + ), + Text( + 'Date Range: ', + style: TextStyle( + letterSpacing: 0.6, + fontSize: 21, + fontWeight: FontWeight.w500, + color: Theme.of(context) + .accentColor), + ), + Text( + _totalDaysFormatted, + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.w400, + color: Theme.of(context) + .accentColor), + ), + ], + ), + ], + ), + ), + if (_availableDatesForTrip != null && _isCollapsed) + Container( + margin: EdgeInsets.only(top: 10), + padding: EdgeInsets.only(left: 5, top: 10), + decoration: BoxDecoration( + color: Color.fromRGBO(53, 56, 63, 1), + borderRadius: + BorderRadius.all(Radius.circular(25))), + child: Column( + children: [ + Row(children: [ + Container( + padding: EdgeInsets.only( + right: 3, + top: 4, + bottom: 7, + left: 15), + child: Icon( + Icons.event_available, + color: Theme.of(context).accentColor, + size: 24, + ), ), - ) - ], + Container( + padding: EdgeInsets.only( + top: 5, left: 5, bottom: 10), + child: Text( + 'Available Dates:', + style: TextStyle( + letterSpacing: 0.6, + fontSize: 21, + fontWeight: FontWeight.w500, + color: Theme.of(context) + .accentColor), + ), + ), + ]), + for (var i = 0; + i < _availableDatesForTrip.length; + i++) + Container( + padding: const EdgeInsets.only( + top: 5, bottom: 15, left: 5), + child: Row( + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + Container( + padding: EdgeInsets.only( + right: 6, left: 12), + child: Icon( + Icons.check_rounded, + color: Theme.of(context) + .accentColor, + size: 20, + ), + ), + Text( + _availableDatesForTrip[i], + style: TextStyle( + letterSpacing: 0.6, + fontSize: 20, + fontWeight: FontWeight.w400, + color: Theme.of(context) + .accentColor), + ), + ], + ), + ) + ], + ), ), - ), - ], - ), + ], + ), ], ); },