颤振使用多个模型与范围模型 [英] Flutter Using Multiple Models with Scoped Model

查看:79
本文介绍了颤振使用多个模型与范围模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Flutter中构建Expense跟踪器应用程序,并决定使用范围模型进行状态管理.该应用程序有一个可以拥有多个帐户的用户,每个帐户可以具有许多交易.

I'm trying to build an Expense tracker App in Flutter and has decided to use Scoped Model for state management. The App has a User who can have many Accounts and each account can have many Transactions.

我如何对这些模型进行建模以与范围模型一起使用,我一直坚持选择好的架构.

How do I model these to be used with Scoped Model, I am stuck on selecting a good Architecture.

如果我创建的用户模型具有一个帐户列表,其中每个帐户都是一个帐户模型,则从AccountModel内部触发和更新不会触发那些访问UserModel类的帐户.

If I create a UserModel that has a list of Accounts where each Account is an AccountModel then triggering and update from inside AccountModel would not trigger the ones accessing the UserModel class.

推荐答案

class CombinedWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final username =
      ScopedModel.of<UserModel>(context, rebuildOnChange: true).username;
    final counter =
      ScopedModel.of<CounterModel>(context, rebuildOnChange: true).counter;

    return Text('$username tapped the button $counter times');

  }
}

您可以在中看到完整的示例.

you can see complete example in source .

这篇关于颤振使用多个模型与范围模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆