feat(wip): implement trip persistence through a local repository. Include loaded trips in the start page UI
This commit is contained in:
65
frontend/lib/presentation/pages/trip_details_page.dart
Normal file
65
frontend/lib/presentation/pages/trip_details_page.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:sliding_up_panel/sliding_up_panel.dart';
|
||||
|
||||
import 'package:anyway/core/constants.dart';
|
||||
import 'package:anyway/domain/entities/trip.dart';
|
||||
import 'package:anyway/presentation/utils/trip_location_utils.dart';
|
||||
import 'package:anyway/presentation/widgets/trip_details_panel.dart';
|
||||
import 'package:anyway/presentation/widgets/trip_map.dart';
|
||||
|
||||
class TripDetailsPage extends StatefulWidget {
|
||||
const TripDetailsPage({super.key, required this.trip});
|
||||
|
||||
final Trip trip;
|
||||
|
||||
@override
|
||||
State<TripDetailsPage> createState() => _TripDetailsPageState();
|
||||
}
|
||||
|
||||
class _TripDetailsPageState extends State<TripDetailsPage> {
|
||||
late Future<bool> _locationPrefFuture;
|
||||
late Future<TripLocaleInfo> _localeFuture;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_locationPrefFuture = _loadLocationPreference();
|
||||
_localeFuture = TripLocationUtils.resolveLocaleInfo(widget.trip);
|
||||
}
|
||||
|
||||
Future<bool> _loadLocationPreference() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getBool('useLocation') ?? true;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: FutureBuilder<TripLocaleInfo>(
|
||||
future: _localeFuture,
|
||||
builder: (context, snapshot) {
|
||||
final locale = snapshot.data;
|
||||
final title = locale?.cityName ?? 'Trip overview';
|
||||
return Text(title);
|
||||
},
|
||||
),
|
||||
),
|
||||
body: FutureBuilder<bool>(
|
||||
future: _locationPrefFuture,
|
||||
builder: (context, snapshot) {
|
||||
final enableLocation = snapshot.data ?? false;
|
||||
return SlidingUpPanel(
|
||||
borderRadius: const BorderRadius.only(topLeft: Radius.circular(24), topRight: Radius.circular(24)),
|
||||
parallaxEnabled: true,
|
||||
maxHeight: MediaQuery.of(context).size.height * TRIP_PANEL_MAX_HEIGHT,
|
||||
minHeight: MediaQuery.of(context).size.height * TRIP_PANEL_MIN_HEIGHT,
|
||||
panelBuilder: (controller) => TripDetailsPanel(trip: widget.trip, controller: controller),
|
||||
body: TripMap(trip: widget.trip, showRoute: true, interactive: true, borderRadius: 0, enableMyLocation: enableLocation),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user