如何解决在发行模式下的flutter apk不能重建小部件,但在调试模式下可以正常工作
更改变量时,无法在提供者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具有互联网许可
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。