|
|
|
@ -1,3 +1,5 @@
|
|
|
|
|
import 'dart:async'; |
|
|
|
|
|
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart'; |
|
|
|
|
import 'package:info_tren/api/station_data.dart'; |
|
|
|
|
import 'package:info_tren/models.dart'; |
|
|
|
@ -32,7 +34,18 @@ final trainInfoArgumentsProvider = Provider<TrainInfoArguments>(
|
|
|
|
|
(_) => throw UnimplementedError('Please override in ProviderScope'), |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
final stationDataProvider = FutureProvider.family((ref, String stationName) => getStationData(stationName)); |
|
|
|
|
final stationDataProvider = FutureProvider.family((ref, String stationName) async { |
|
|
|
|
final data = await getStationData(stationName); |
|
|
|
|
|
|
|
|
|
final timer = Timer(const Duration(minutes: 2), () { |
|
|
|
|
ref.invalidateSelf(); |
|
|
|
|
}); |
|
|
|
|
ref.onDispose(() { |
|
|
|
|
timer.cancel(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
return data; |
|
|
|
|
}); |
|
|
|
|
final viewStationArgumentsProvider = Provider<ViewStationArguments>( |
|
|
|
|
(_) => throw UnimplementedError('Please override in ProviderScope'), |
|
|
|
|
); |
|
|
|
@ -40,4 +53,4 @@ final viewStationDataProvider = Provider((ref) {
|
|
|
|
|
final args = ref.watch(viewStationArgumentsProvider); |
|
|
|
|
final data = ref.watch(stationDataProvider(args.stationName)); |
|
|
|
|
return data; |
|
|
|
|
}); |
|
|
|
|
}, dependencies: [viewStationArgumentsProvider, stationDataProvider]); |
|
|
|
|