问题描述
这是我用于 Mobx 函数和变量设置的 Cart.dart 文件
'''
import 'package:mobx/mobx.dart';
import 'package:mobx_simple_example/shared/models/product.dart';
part 'cart.g.dart';
class Cart = _Cart with _$Cart;
abstract class _Cart with Store {
//Todo: 1. Add state management with a cart of products
// @observable show Error #注解创建只能调用const构造函数
@Observable
ObservableList<Product> _cartContent = ObservableList<Product>();
ObservableList<Product> get cartContent => _cartContent;
@Computed
List<Product> get uniqueProducts =>
ObservableList.of(_cartContent).toSet().toList();
}
'''
'''
import 'package:Flutter/
widgets.dart';
import 'package:mobx_simple_example/shared/utils/app_variables.dart';
class Product {
Product({
@required this.name,@required this.description,@required this.category,@required this.price,@required this.imageURL,});
我将构造函数更改为 const 但它不起作用..
final String? name;
final String? description;
final Category? category;
final double? price;
final String? imageURL;
@override
bool operator ==(dynamic o) => o is Product && o.name == name;
@override
int get hashCode => name.hashCode;
}
'''
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)