Skip to content

Allow @SolidQuery to react to a different @SolidQuery #5

@NabilaWorks

Description

@NabilaWorks

Modified example :

class QueryWithStreamAndSourceExample extends StatelessWidget {
  QueryWithStreamAndSourceExample({super.key});

  @SolidState()
  int multiplier = 1;

  @SolidQuery(useRefreshing: false)
  Stream<int> fetchData() {
    return Stream.periodic(const Duration(seconds: 1), (i) => i * multiplier);
  }

  @SolidQuery(useRefreshing: false)
  Future<double> fetchDataFromQuery() async {
    final stream = fetchData();
    var lastValue = 0.0;
    await for (final value in stream) {
      lastValue = value.toDouble();
    }
    return lastValue / 3;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('QueryWithStream')),
      body: Center(
        child: Column(
          children: [
            Text('Is refreshing: ${fetchDataFromQuery().isRefreshing}'),
            fetchDataFromQuery().when(
              ready: (data) => Text(data.toString()),
              loading: CircularProgressIndicator.new,
              error: (error, stackTrace) => Text('Error: $error'),
            ),
            ElevatedButton(
              onPressed: fetchData.refresh,
              child: const Text('Manual Refresh'),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => multiplier++,
        child: const Icon(Icons.add),
      ),
    );
  }
}

Unfortunately this arbitrary example doesn't work currently :

  @SolidQuery(useRefreshing: false)
  Future<double> fetchDataFromQuery() async {
    final stream = fetchData();
    var lastValue = 0.0;
    await for (final value in stream) {
      lastValue = value.toDouble();
    }
    return lastValue / 3;
  }

We would need a way to get the current value of the @SolidQuery in another reactive @SolidQuery, is there a way to do something like this currently or perhaps a workaround?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions