provider
provider copied to clipboard
NotifyListener() not working in release build (android)
I am using latest version of provider but in my project notifyListener() is working fine in debug mode but When I try to check same code in release mode then notifyListener() is not working and no action performing. I also used consumer but not updating the widget in release mode.
please resolve the issue as soon as possible
Please provide enough code to reproduce the problem.
Same issue.
same issue
Please, for the love of gods, stop commenting "same issue".
Like I said, I need a way to reproduce the problem. If you don't give me a way to reproduce the problem, it's impossible for me to help you.
The only thing this kind of comment does is frustrate me.
void removeSelectedAccount(SelectedAccount value, double walletBalance) { try { print("removeSelectedAccount"); _selectdAccounts .removeWhere((element) => element.accountName == value.accountName); print("removeSelectedAccount"); settotalAmountCollected(walletBalance); } catch (e) { toast("Error: $e"); } } void settotalAmountCollected(double walletBalance) { try { print("settotalAmountCollected"); if (_selectdAccounts.isEmpty) { _totalAmountCollected = 0; _amountToCollect = _amount! - walletBalance; notifyListeners(); return; } _totalAmountCollected = walletBalance;
_amountToCollect = 0;
_selectdAccounts.forEach((element) {
_totalAmountCollected =
_totalAmountCollected + double.parse(element.amountSeected);
_amountToCollect = amount! - _totalAmountCollected;
});
notifyListeners();
} catch (e) {
toast("Error: $e");
}
}
Widget button() { final TransacionProvider transferProvider = Provider.of<TransacionProvider>(context); final _size = MediaQuery.of(context).size; if (transferProvider.amountToCollect == null) { return buttonWraper( Text( "Insufficient Balance", style: getRegularStyle(color: ColorManager.whiteText, fontSize: 14), ), ColorManager.errorRed); } if (transferProvider.amountToCollect == 0) { return ConfirmationSlider( foregroundColor: ColorManager.background, sliderButtonContent: Shimmer.fromColors( baseColor: Color.fromARGB(255, 255, 255, 255), highlightColor: Color.fromARGB(255, 13, 13, 13), child: Icon( Icons.arrow_forward_ios_rounded, color: Colors.white, size: _size.width * 0.07, ), ), height: 60, width: 280, onConfirmation: () { validateData(); }, backgroundColor: ColorManager.grayLight, text: "Slide to Pay", textStyle: getBoldtStyle( color: ColorManager.whiteText, fontSize: 14, ), // stickToEnd: true, ); }
if (transferProvider.amountToCollect! < 0) {
return buttonWraper(
Text(
"Exceeded amount required ",
style: getRegularStyle(color: ColorManager.whiteText, fontSize: 14),
),
ColorManager.grayLight,
);
}
if (transferProvider.amountToCollect! > 0) {
return buttonWraper(
Text(
" Please add \$${transferProvider.amountToCollect!.toStringAsFixed(2)} more.",
style:
getRegularStyle(color: ColorManager.whiteText, fontSize: 14)),
Color.fromARGB(255, 144, 169, 121));
}
return Container();
}
when i remove or add account its not updating button as it is supposed to be,it working fine in debug mode
Widget build(BuildContext context) { return MultiProvider( providers: [ ChangeNotifierProvider(create: () => DataProvider()), ChangeNotifierProvider(create: () => AnimationProvider()), ChangeNotifierProvider(create: () => BusinessRegistrationProvider()), ChangeNotifierProvider(create: () => WalletProvider()), ChangeNotifierProvider(create: () => BankProvider()), ChangeNotifierProvider(create: () => ProfileProvider()), ChangeNotifierProvider(create: () => TransacionProvider()), ChangeNotifierProvider(create: () => TransacationhistoryProvider()), ], child: MaterialApp( title: 'Finwallet', debugShowCheckedModeBanner: false, theme: getApplicationTheme(context).copyWith(useMaterial3: true), onGenerateRoute: RouteGenerator.getRoute, initialRoute: Routes.splashRoute, ), ); }
@rrousselGit is there any mistake in this code
Thanks! Could you update your example such that it compiles? There's not much I can do with this, as I can't run it.
@rrousselGit I found the issue let me explain im working in a mobile application which used to transfer money there are two screens one for entering amount 2nd one for selecting bank account the issue was rebuilding process was not happening even after calling notify listeners in the second screen. but the problem was in 1st screen what i was doing is in the 1st screen which mean int the amount entering screen's init state methode i was calling the following code .................................................................... @override void initState() { super.initState(); final transactionProvider = Provider.of<TransacionProvider>(context, listen: false); transactionProvider.setrecipient(widget.recipient); } ................................................................... the transaction provide contains the following code ................................................................... class TransacionProvider with ChangeNotifier { Recipient? _recipient; Recipient? get recipient => _recipient;
void setrecipient(Recipient? value) { _recipient = value; } List<SelectedAccount> _selectdAccounts = []; List<SelectedAccount> get selectdAccounts => _selectdAccounts;
void insertSelectedAccount(SelectedAccount value, double walletBalance) { _selectdAccounts .removeWhere((element) => element.accountName == value.accountName); _selectdAccounts.add(value); settotalAmountCollected(walletBalance); notifyListeners(); }
void removeSelectedAccount(SelectedAccount value, double walletBalance) { print("removeSelectedAccount"); _selectdAccounts .removeWhere((element) => element.accountName == value.accountName); print("removeSelectedAccount"); settotalAmountCollected(walletBalance); notifyListeners(); }
double _totalAmountCollected = 0; double get totalAmountCollected => _totalAmountCollected;
void settotalAmountCollected(double walletBalance) { print("settotalAmountCollected"); if (_selectdAccounts.isEmpty) { _totalAmountCollected = 0; _amountToCollect = _amount! - walletBalance;
notifyListeners();
return;
}
_totalAmountCollected = walletBalance;
_amountToCollect = 0;
_selectdAccounts.forEach((element) {
_totalAmountCollected =
_totalAmountCollected + double.parse(element.amountSeected);
_amountToCollect = amount! - _totalAmountCollected;
});
notifyListeners();
} } ...................................................................
i have confirm button in second screen(bank account selecting screen) which is supposed to change as user select or remove a bank account using the above function,the function was calling successfully in both release and debug mode but the rebuilding process was only happened in debug mode so i changed the 1st screen initState methode as follows ................................................................... void initState() { super.initState(); WidgetsBinding.instance.addPostFrameCallback((_) { final transactionProvider = Provider.of<TransacionProvider>(context, listen: false); transactionProvider.setrecipient(widget.recipient); }); } ................................................................... and it starts working very fine........ i hope this will be helpful, i'm still not able to understand why it worked in debug and not in release mode??
Please, for the love of gods, stop commenting "same issue".
Like I said, I need a way to reproduce the problem. If you don't give me a way to reproduce the problem, it's impossible for me to help you.
The only thing this kind of comment does is frustrate me.
Perhaps a better issues template could help
https://github.com/VeryGoodOpenSource/very_good_cli/tree/main/.github
Please, for the love of gods, stop commenting "same issue".
Like I said, I need a way to reproduce the problem. If you don't give me a way to reproduce the problem, it's impossible for me to help you.
The only thing this kind of comment does is frustrate me.
Hey, fancy creating a Github action or installing Apps from the marketplace to monitor the issues with specific rules? Just to prevent not-so-helpful
or not-detailed
comments as the above.
@johnmelodyme I've never heard about those. Any specific tool in mind?
@johnmelodyme I've never heard about those. Any specific tool in mind?
I am glad you asked. :)
option 1, Using GitHub action like this https://github.com/flutter/flutter/tree/master/.github/workflows option 2, Use Stale as used by jitsi_meet
Thanks!
How do these tools help with unhelpful comments?
Afaik they seem to focus on closing issues that don't get reactions
Le mar. 30 août 2022 à 12:29, John Melody Me @.***> a écrit :
@johnmelodyme https://github.com/johnmelodyme I've never heard about those. Any specific tool in mind?
I am glad you asked. :)
option 1, Using GitHub action like this https://github.com/flutter/flutter/tree/master/.github/workflows option 2, Use Stale https://github.com/apps/stale as used by jitsi_meet https://github.com/gunschu/jitsi_meet/issues/393#issuecomment-1230064925
— Reply to this email directly, view it on GitHub https://github.com/rrousselGit/provider/issues/763#issuecomment-1231476385, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEZ3I3OFQ2JKPU4IYCKGH7LV3XPCJANCNFSM52TAFJPQ . You are receiving this because you were mentioned.Message ID: @.***>
I came here with a similar issue, and found that my problem was solved similartly to bazl-E. In debug mode my app was working although it was throwing an error that I wasn't paying attention to: setState() or markNeedsBuild() called during build.
.
I had some code that was indeed inadvertently calling notifyListeners()
in my build function, and while it worked in debug mode, it didn't in release mode. I fixed this by wrapping the call in a WidgetsBinding.instance.addPostFrameCallback()
.
I came here with a similar issue, and found that my problem was solved similartly to bazl-E. In debug mode my app was working although it was throwing an error that I wasn't paying attention to:
setState() or markNeedsBuild() called during build.
.I had some code that was indeed inadvertently calling
notifyListeners()
in my build function, and while it worked in debug mode, it didn't in release mode. I fixed this by wrapping the call in aWidgetsBinding.instance.addPostFrameCallback()
.
I face same iussue. My solution is to remove unnecessary notifyListeners()
in build function. And then everything looks fine.
I came here with a similar issue, and found that my problem was solved similartly to bazl-E. In debug mode my app was working although it was throwing an error that I wasn't paying attention to:
setState() or markNeedsBuild() called during build.
.I had some code that was indeed inadvertently calling
notifyListeners()
in my build function, and while it worked in debug mode, it didn't in release mode. I fixed this by wrapping the call in aWidgetsBinding.instance.addPostFrameCallback()
.
Same, i wasn't paying attention to `setState() or markNeedsBuild()' error because tried to debug it via chrome and didn't see any readable error in console. All further attempts to call notifiyListeners() doesn't perform widget rebuild in release mode. I think it would be fair the same behavior for debug mode
Thanks for your comments everyone. I finally understand a bit more about the issue
If it's caused by people incorrectly calling notifyListeners
within build
and ignoring the error message, I'm not sure there's anything I can do.
The best I could do is change the error message. But if it's ignored to begin with, I doubt it's going to do much
Closing since this isn't a Provider issue