1- import 'package:flutter/material.dart' ;
21import 'package:flutter/material.dart' ; // Ensure Material is imported
32import 'package:weekend_gateway/presentation/common/neo_button.dart' ;
43import 'package:weekend_gateway/presentation/common/neo_text_field.dart' ;
@@ -9,8 +8,6 @@ import 'package:weekend_gateway/services/trip_service.dart'; // For saving the t
98import 'package:weekend_gateway/config/supabase_config.dart' ; // For current user ID
109import 'package:weekend_gateway/presentation/screens/trip/trip_detail_screen.dart' ; // For navigation
1110import 'package:weekend_gateway/presentation/common/neo_card.dart' ; // For displaying trip details
12- import 'package:weekend_gateway/models/trip_day_model.dart' ; // For displaying days/activities
13- import 'package:weekend_gateway/models/trip_activity_model.dart' ; // For displaying activities
1411
1512class AIItineraryGeneratorScreen extends StatefulWidget {
1613 const AIItineraryGeneratorScreen ({Key ? key}) : super (key: key);
@@ -24,11 +21,10 @@ class _AIItineraryGeneratorScreenState extends State<AIItineraryGeneratorScreen>
2421 final _destinationController = TextEditingController ();
2522 final _durationController = TextEditingController ();
2623 final _interestsController = TextEditingController ();
27- String ? _selectedBudget = 'mid-range' ;
24+ String ? _selectedBudget = 'mid-range' ;
2825
2926 bool _isLoading = false ;
3027 TripModel ? _generatedTrip;
31- String ? _rawApiResponse; // To display raw response for debugging if needed
3228 final AIService _aiService = AIService ();
3329 final TripService _tripService = TripService (); // For saving
3430
@@ -47,7 +43,6 @@ class _AIItineraryGeneratorScreenState extends State<AIItineraryGeneratorScreen>
4743 setState (() {
4844 _isLoading = true ;
4945 _generatedTrip = null ;
50- _rawApiResponse = null ;
5146 });
5247
5348 final preferences = {
@@ -69,11 +64,11 @@ class _AIItineraryGeneratorScreenState extends State<AIItineraryGeneratorScreen>
6964
7065 setState (() {
7166 _generatedTrip = trip;
72- _rawApiResponse = rawResponse; // Optional: for display/debug
7367 _isLoading = false ;
7468 });
7569
7670 if (trip == null ) {
71+ if (! context.mounted) return ;
7772 ScaffoldMessenger .of (context).showSnackBar (
7873 const SnackBar (content: Text ('Failed to parse AI response. Please try again.' )),
7974 );
@@ -83,6 +78,7 @@ class _AIItineraryGeneratorScreenState extends State<AIItineraryGeneratorScreen>
8378 setState (() {
8479 _isLoading = false ;
8580 });
81+ if (! context.mounted) return ;
8682 ScaffoldMessenger .of (context).showSnackBar (
8783 SnackBar (content: Text ('Error generating itinerary: $e ' )),
8884 );
@@ -95,6 +91,7 @@ class _AIItineraryGeneratorScreenState extends State<AIItineraryGeneratorScreen>
9591
9692 final currentUserId = SupabaseConfig .client.auth.currentUser? .id;
9793 if (currentUserId == null ) {
94+ if (! context.mounted) return ;
9895 ScaffoldMessenger .of (context).showSnackBar (
9996 const SnackBar (content: Text ('You need to be logged in to save itineraries.' )),
10097 );
@@ -118,8 +115,8 @@ class _AIItineraryGeneratorScreenState extends State<AIItineraryGeneratorScreen>
118115 'description' : activity.description,
119116 'location' : activity.location, // This is location_name from AI
120117 'time' : activity.time,
121- 'latitude' : activity.latitude,
122- 'longitude' : activity.longitude,
118+ // 'latitude': activity.latitude, // TODO: Fix this
119+ // 'longitude': activity.longitude, // TODO: Fix this
123120 // photo_urls will be empty by default from parseApiResponse
124121 };
125122 }).toList (),
@@ -132,10 +129,12 @@ class _AIItineraryGeneratorScreenState extends State<AIItineraryGeneratorScreen>
132129 _isLoading = false ;
133130 });
134131
132+ if (! context.mounted) return ;
135133 ScaffoldMessenger .of (context).showSnackBar (
136134 const SnackBar (content: Text ('AI Itinerary saved successfully!' )),
137135 );
138136 // Navigate to the new trip's detail screen
137+ if (! context.mounted) return ;
139138 Navigator .pushReplacement (
140139 context,
141140 MaterialPageRoute (builder: (context) => TripDetailScreen (tripId: savedTripId)),
@@ -145,6 +144,7 @@ class _AIItineraryGeneratorScreenState extends State<AIItineraryGeneratorScreen>
145144 setState (() {
146145 _isLoading = false ;
147146 });
147+ if (! context.mounted) return ;
148148 ScaffoldMessenger .of (context).showSnackBar (
149149 SnackBar (content: Text ('Error saving itinerary: $e ' )),
150150 );
@@ -173,7 +173,7 @@ class _AIItineraryGeneratorScreenState extends State<AIItineraryGeneratorScreen>
173173 NeoTextField (
174174 controller: _destinationController,
175175 hintText: 'E.g., Paris, Tokyo, Bali' ,
176- labelText: 'Destination*' ,
176+ decoration : const InputDecoration ( labelText: 'Destination*' ) ,
177177 validator: (value) {
178178 if (value == null || value.isEmpty) {
179179 return 'Please enter a destination' ;
@@ -185,7 +185,7 @@ class _AIItineraryGeneratorScreenState extends State<AIItineraryGeneratorScreen>
185185 NeoTextField (
186186 controller: _durationController,
187187 hintText: 'E.g., 3, 5, 7' ,
188- labelText: 'Duration (days)*' ,
188+ decoration : const InputDecoration ( labelText: 'Duration (days)*' ) ,
189189 keyboardType: TextInputType .number,
190190 validator: (value) {
191191 if (value == null || value.isEmpty) {
@@ -201,7 +201,7 @@ class _AIItineraryGeneratorScreenState extends State<AIItineraryGeneratorScreen>
201201 NeoTextField (
202202 controller: _interestsController,
203203 hintText: 'E.g., food, history, hiking, art' ,
204- labelText: 'Interests*' ,
204+ decoration : const InputDecoration ( labelText: 'Interests*' ) ,
205205 validator: (value) {
206206 if (value == null || value.isEmpty) {
207207 return 'Please enter your interests' ;
@@ -250,11 +250,6 @@ class _AIItineraryGeneratorScreenState extends State<AIItineraryGeneratorScreen>
250250 const Center (child: CircularProgressIndicator ()),
251251 if (_generatedTrip != null )
252252 _buildGeneratedItineraryReview (),
253- // if (_rawApiResponse != null) // For debugging raw response
254- // Padding(
255- // padding: const EdgeInsets.only(top: 16.0),
256- // child: Text("Raw AI Response:\n$_rawApiResponse"),
257- // ),
258253 ],
259254 ),
260255 ),
@@ -282,8 +277,8 @@ class _AIItineraryGeneratorScreenState extends State<AIItineraryGeneratorScreen>
282277 const SizedBox (height: 8 ),
283278 Text ('Description: ${_generatedTrip !.description ?? "No description provided." }' , style: Theme .of (context).textTheme.bodyMedium),
284279 const SizedBox (height: 8 ),
285- if (_generatedTrip! .latitude != null && _generatedTrip! .longitude != null )
286- Text ('Coordinates: ${_generatedTrip !.latitude }, ${_generatedTrip !.longitude }' , style: Theme .of (context).textTheme.bodySmall),
280+ // if (_generatedTrip!.latitude != null && _generatedTrip!.longitude != null) // TODO: Fix this
281+ // Text('Coordinates: ${_generatedTrip!.latitude}, ${_generatedTrip!.longitude}', style: Theme.of(context).textTheme.bodySmall),
287282 const SizedBox (height: 8 ),
288283 Text ('Price Level: ${_budgetOptions .firstWhere ((b ) => _getMockPriceLevel (b ) == _generatedTrip !.priceLevel , orElse : () => "N/A" ).toUpperCase ()}' , style: Theme .of (context).textTheme.bodyMedium),
289284 const SizedBox (height: 16 ),
@@ -309,8 +304,8 @@ class _AIItineraryGeneratorScreenState extends State<AIItineraryGeneratorScreen>
309304 if (activity.description != null ) Text (activity.description! ),
310305 if (activity.location != null ) Text ('Location: ${activity .location }' , style: Theme .of (context).textTheme.bodySmall),
311306 if (activity.time != null ) Text ('Time: ${activity .time }' , style: Theme .of (context).textTheme.bodySmall),
312- if (activity.latitude != null && activity.longitude != null )
313- Text ('Coords: ${activity .latitude !.toStringAsFixed (4 )}, ${activity .longitude !.toStringAsFixed (4 )}' , style: Theme .of (context).textTheme.bodySmall),
307+ // if (activity.latitude != null && activity.longitude != null) // TODO: Fix this
308+ // Text('Coords: ${activity.latitude!.toStringAsFixed(4)}, ${activity.longitude!.toStringAsFixed(4)}', style: Theme.of(context).textTheme.bodySmall),
314309 ],
315310 ),
316311 );
@@ -319,6 +314,7 @@ class _AIItineraryGeneratorScreenState extends State<AIItineraryGeneratorScreen>
319314 },
320315 ),
321316 const SizedBox (height: 24 ),
317+ const SizedBox (height: 24 ),
322318 NeoButton (
323319 onPressed: _isLoading ? null : _saveGeneratedItinerary,
324320 isLoading: _isLoading && _generatedTrip != null , // Show loading for saving
0 commit comments