[SYNC]
This commit is contained in:
@@ -19,6 +19,7 @@ class AstromicFuturePresenter<T> extends StatefulWidget {
|
||||
//SECTION - Widget Arguments
|
||||
final AstromicPresenterController controller;
|
||||
final String id;
|
||||
final Map<String,dynamic>? neededArguments;
|
||||
//
|
||||
final Map<AstromicPresenterState, Widget Function(PresenterReturnModel<T?>? r)> stateBuilder;
|
||||
final AstromicPresenterConfiguration? configuration;
|
||||
@@ -30,6 +31,8 @@ class AstromicFuturePresenter<T> extends StatefulWidget {
|
||||
required this.id,
|
||||
required this.stateBuilder,
|
||||
this.configuration,
|
||||
this.neededArguments,
|
||||
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -128,6 +131,7 @@ class _AstromicFuturePresenterState<T> extends State<AstromicFuturePresenter<T>>
|
||||
|
||||
//S1 -- Method to reinitialize or update `_future` with a new instance
|
||||
void _initializeFuture() {
|
||||
widget.controller.setProvidedArguments(widget.neededArguments ?? <String,dynamic>{});
|
||||
_future = widget.controller.getFuture(widget.id)?.then((dynamic result) => result as T?);
|
||||
}
|
||||
//!SECTION
|
||||
|
||||
@@ -3,14 +3,14 @@ import 'dart:async';
|
||||
|
||||
/// A contrller used to control Futures/Streams to present them effeciantly.
|
||||
class AstromicPresenterController {
|
||||
late final Map<String, (Future Function()? fetch, int c)> _futures;
|
||||
late final Map<String, (Future Function(Map<String, dynamic> args)? fetch, int c)> _futures;
|
||||
late final Map<String, Stream Function(Map<String, dynamic> args)?> _streams;
|
||||
late final Map<String, StreamController<void>> _futureRefreshers;
|
||||
|
||||
|
||||
|
||||
AstromicPresenterController({
|
||||
Map<String, (Future Function()? fetch, int startCycle)> futures = const {},
|
||||
Map<String, (Future Function(Map<String, dynamic> args)? fetch, int startCycle)> futures = const {},
|
||||
Map<String, Stream Function(Map<String, dynamic> args)?> streams = const {},
|
||||
}) : _futures = futures.map((k, v) => MapEntry(k, (v.$1, v.$2))),
|
||||
_futureRefreshers = futures.map((k, v) => MapEntry(k, StreamController<void>.broadcast())),
|
||||
@@ -35,7 +35,7 @@ class AstromicPresenterController {
|
||||
Future<T?>? getFuture<T>(String id) {
|
||||
assert(_futures.containsKey(id), 'did you add a future with this id?');
|
||||
|
||||
return _futures[id]!.$1!() as Future<T?>?;
|
||||
return _futures[id]!.$1!(getProvidedArguments()) as Future<T?>?;
|
||||
}
|
||||
|
||||
/// Get the stream using it's ID.
|
||||
|
||||
Reference in New Issue
Block a user