forked from OpenFlutter/Flutter-Notebook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
更新 provider 到 4.0 新增 selector 的使用样例
- Loading branch information
Showing
4 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
mecury_project/example/provider_example/lib/goods_model.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:flutter/material.dart' show ChangeNotifier; | ||
|
||
class GoodsListProvider with ChangeNotifier { | ||
List<Goods> _goodsList = | ||
List.generate(10, (index) => Goods(false, 'Goods No. $index')); | ||
|
||
get goodsList => _goodsList; | ||
get total => _goodsList.length; | ||
|
||
collect(int index) { | ||
var good = _goodsList[index]; | ||
_goodsList[index] = Goods(!good.isCollection, good.goodsName); | ||
notifyListeners(); | ||
} | ||
} | ||
|
||
class Goods { | ||
final bool isCollection; | ||
final String goodsName; | ||
|
||
Goods(this.isCollection, this.goodsName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters