ufan0
V2EX  ›  Flutter

此类场景在 Flutter 中的最佳实践是什么?

  •  
  •   ufan0 · Aug 30, 2024 · 2270 views
    This topic created in 639 days ago, the information mentioned may be changed or developed.

    场景描述

    技术栈 Flutter+Drift+Riverpod ,有表todoRecorduser,现在需要查询出待办记录最多的五位用户,使用图表展示,并能够支持自动刷新

    1. 查询todoRecord表,定位到userId出现次数最多的五条userId
    2. 查询user表拿到用户信息如姓名;
    3. 绘制图表。

    方案

    因为需要实现自动刷新,那么使用到了 Drift 的 watch()函数返回 Stream 。

    • 方案 1 ,分两次查询: StreamBuilder<List<TodoRecordData>>嵌套StreamBuilder<List<UserData>>
    • 方案 2 ,一次查询:自定义 SQL 处理连表查询,直接单StreamBuilder<List<(UserData, int)>>构建。
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2489 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 15:58 · PVG 23:58 · LAX 08:58 · JFK 11:58
    ♥ Do have faith in what you're doing.