-
I just have a simple question that I couldn't find any answer by checking the documentation, as I mentioned in the issue title, is it okay to use single Observer widget for observable/computed from multiple store instances? or should I create another Observer widget for each store instance? E.g: Storespart 'test_store_1.g.dart';
class TestStore1 = _TestStore1 with _$TestStore1;
abstract class _TestStore1 with Store {
@readonly
ObservableFuture<SomeViewData>? _someViewDataObservableFuture;
@computed
bool get isLoading => _someViewDataObservableFuture?.status == FutureStatus.pending;
@action
void getSomeViewData() {
_someViewDataObservableFuture = ObservableFuture(
_someUseCase.call(),
);
}
} part 'test_store_2.g.dart';
class TestStore2 = _TestStore2 with _$TestStore2;
abstract class _TestStore2 with Store {
@readonly
ObservableFuture<SomeViewData2>? _someViewDataObservableFuture2;
@computed
bool get isLoading2 => _someViewDataObservableFuture2?.status == FutureStatus.pending;
@action
void getSomeViewData2() {
_someViewDataObservableFuture2 = ObservableFuture(
_someUseCase2.call(),
);
}
} UIWidget build(BuildContext context) {
final testStore1 = context.read<TestStore1>();
final testStore2 = context.read<TestStore2>();
// WAY 1
return Observer(
builder: (context) => testStore1.isLoading || testStore2.isLoading
? CircularProgressIndicator()
: SomeOtherWidget(),
);
// WAY 2
return Observer(
builder: (context) => testStore1.isLoading
? Observer(
builder: (context) => testStore2.isLoading
? CircularProgressIndicator()
: SomeOtherWidget(),
)
: CircularProgressIndicator(),
);
} |
Beta Was this translation helpful? Give feedback.
Answered by
amondnet
Jul 16, 2024
Replies: 1 comment
-
@memishood |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
amondnet
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@memishood
It depends on your situation, but in the example described above, you can use only one. It is recommended to separate observers into widgets that need to be rebuilt, not by the number of observables.