import 'dart:collection'; import 'package:fast_network_navigation/modules/landmark_card.dart'; import 'package:fast_network_navigation/structs/landmark.dart'; import 'package:fast_network_navigation/structs/trip.dart'; import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; class LandmarksOverview extends StatefulWidget { final Future? trip; const LandmarksOverview({super.key, this.trip}); @override State createState() => _LandmarksOverviewState(); } class _LandmarksOverviewState extends State { // final Future> _landmarks = fetchLandmarks(); @override Widget build(BuildContext context) { final Future> _landmarks = getLandmarks(widget.trip); return DefaultTextStyle( style: Theme.of(context).textTheme.displayMedium!, textAlign: TextAlign.center, child: FutureBuilder>( future: _landmarks, builder: (BuildContext context, AsyncSnapshot> snapshot) { List children; if (snapshot.hasData) { children = [landmarksWithSteps(snapshot.data!), saveButton()]; } else if (snapshot.hasError) { children = [ const Icon( Icons.error_outline, color: Colors.red, size: 60, ), Padding( padding: const EdgeInsets.only(top: 16), child: Text('Error: ${snapshot.error}', style: TextStyle(fontSize: 12)), ), ]; } else { children = [Center(child: CircularProgressIndicator())]; } return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: children, ), ); }, ), ); } Widget saveButton() => ElevatedButton( onPressed: () async { Trip? trip = await widget.trip; SharedPreferences prefs = await SharedPreferences.getInstance(); trip?.toPrefs(prefs); }, child: const Text('Save'), ); } Widget landmarksWithSteps(LinkedList landmarks) { List children = []; for (Landmark landmark in landmarks) { children.add(LandmarkCard(landmark)); if (landmark.next != null) { Widget step = stepBetweenLandmarks(landmark, landmark.next!); children.add(step); } } return Column( children: children ); } Widget stepBetweenLandmarks(Landmark before, Landmark after) { // This is a simple widget that draws a line between landmark-cards // It's a vertical dotted line // Next to the line is the icon for the mode of transport (walking for now) and the estimated time // There is also a button to open the navigation instructions as a new intent return Container( margin: EdgeInsets.all(10), padding: EdgeInsets.all(10), decoration: BoxDecoration( border: Border( left: BorderSide(width: 3.0, color: Colors.black), ), // gradient: LinearGradient( // begin: Alignment.topLeft, // end: Alignment.bottomRight, // colors: [Colors.grey, Colors.white, Colors.white], // ), ), child: Row( children: [ Column( children: [ Icon(Icons.directions_walk), Text("5 min", style: TextStyle(fontSize: 10)), ], ), Spacer(), ElevatedButton( onPressed: () { // Open navigation instructions }, child: Text("Navigate"), ), ], ), ); } Future> getLandmarks (Future? trip) async { Trip tripf = await trip!; return tripf.landmarks; }