更改变量时,无法在提供者notifyListeners()上重建无状态窗口小部件。它仅在发布模式下发生,而在调试模式下一切都很好。
我的pubspec.yaml文件
name: lomaysowda
description: Lomay Sowda elektron sowda komekcisi
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
http: ^0.12.1
carousel_pro: ^1.0.0
clip_shadow: any
flutter_icons: ^1.1.0
flutter_bloc: ^4.0.1
bloc: ^4.0.0
equatable: ^1.2.0
badges: ^1.1.1
styled_text: ^1.0.1+1
flutter_svg: ^0.18.0
sqflite: ^1.3.1
device_info: ^0.4.2+4
path_provider: ^1.6.11
provider: ^4.3.1
cached_network_image: ^2.2.0+1
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- images/
我与提供者的main.dart
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await DbHelper.init();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<ProviderModel>(
create: (context) => ProviderModel(Services()),
child: ...
...
}
providerModel.dart
class ProviderModel with ChangeNotifier{
List<CartItem> _cartItems;
String _apiAddress;
List<CartItem> get GetCartItems=>_cartItems;
void set SetCartItems(List<CartItem> cartItems){
_cartItems=cartItems;
print("DkPrint PushNotifyListeners _cartItems changed");
notifyListeners();
}
}
使用providerModel的无状态小部件
class ResourceItem extends StatelessWidget {
...
@override
Widget build(BuildContext context) {
final providerModel = Provider.of<ProviderModel>(context);
int _orderCount = providerModel.GetCartItems.firstWhere(
(element) => element.ResId == _resource.ResId,
orElse: () => CartItem()).ItemCount ??
0;
return ...
...
Column(children: <Widget>[
(_orderCount > 0)
? CounterWidgets(_orderCount, _resource)
: Container(
width: 0,
),
...
])
...
我对AndroidMainfest.xml具有互联网许可