diff --git a/example/lib/03_2_depends_on_async/depends_on_async_sample.dart b/example/lib/03_2_depends_on_async/depends_on_async_sample.dart index 8a5c6d5..a17b89e 100644 --- a/example/lib/03_2_depends_on_async/depends_on_async_sample.dart +++ b/example/lib/03_2_depends_on_async/depends_on_async_sample.dart @@ -16,6 +16,7 @@ class DependObservableAsyncSampleLayoutState late Telescope weight; late Telescope bmi; late Telescope showingText; + var loadingBMI = Telescope(false); @override void initState() { @@ -26,11 +27,12 @@ class DependObservableAsyncSampleLayoutState bmi = Telescope.dependsOnAsync(0, [height, weight], () async { return await calculateBMI(height.value, weight.value); - }); + }, isCalculating: loadingBMI); - showingText = Telescope.dependsOn([height, weight, bmi], () { + showingText = Telescope.dependsOn([height, weight, bmi, loadingBMI], () { var bmis = bmi.value.toString(); - bmis = bmis.length > 5 ? bmis.substring(0, 5) : bmis; + bmis = loadingBMI.value ? "..." : bmis.length > 5 ? bmis.substring(0, 5) : bmis; + return "weight is ${weight.value} and height is ${height.value} so bmi will be $bmis"; }); } diff --git a/lib/src/telescope.dart b/lib/src/telescope.dart index b346afe..72c9944 100644 --- a/lib/src/telescope.dart +++ b/lib/src/telescope.dart @@ -46,15 +46,22 @@ class Telescope { /// Use this if you need to use await in calculate function Telescope.dependsOnAsync( this.holden, List dependencies, Future Function() calculate, - {this.iWillCallNotifyAll = false}) { + { + this.iWillCallNotifyAll = false, + Telescope? isCalculating, + }) { + isCalculating?.value = true; calculate().then((value) { holden = value; + isCalculating?.value = false; notifyAll(); }); for (var o in dependencies) { o.subscribe(() { + isCalculating?.value = true; calculate().then((value) { holden = value; + isCalculating?.value = false; notifyAll(); }); });