Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not updating stateless widget inside statfulwidget #77146

Closed
Marko1994 opened this issue Mar 3, 2021 · 3 comments
Closed

Not updating stateless widget inside statfulwidget #77146

Marko1994 opened this issue Mar 3, 2021 · 3 comments
Labels
r: invalid Issue is closed as not valid

Comments

@Marko1994
Copy link

Continuously trying to solve this exception but no luck
Please help

@TahaTesser
Copy link
Member

Hi @Marko1994
Please read the docs for widgets and you can find lots of resources on Youtube and Google as well. Please see https://flutter.dev/community for resources and asking questions like this,
you may also get some help if you post it on Stack Overflow and if you need help with your code, please see https://www.reddit.com/r/flutterhelp/
Closing, as this isn't an issue with Flutter itself. If you disagree, please write in the comments and I will reopen it.
Thank you

@TahaTesser TahaTesser added in triage Presently being triaged by the triage team r: invalid Issue is closed as not valid and removed in triage Presently being triaged by the triage team labels Mar 3, 2021
@Marko1994
Copy link
Author

This is my Class
`import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

import '../constants.dart';

class PaymentScreenTest extends StatefulWidget {
static String id = 'Payment_Screen_Test';
@OverRide
_PaymentScreenTestState createState() => _PaymentScreenTestState();
}

class _PaymentScreenTestState extends State {
String lPrice = '1000';

@OverRide
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
Column(
children: [
ClipPath(
clipper: MyClipper(),
child: Container(
height: MediaQuery.of(context).size.height / 2.8,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color(int.parse(kAppBlueColor)),
Color(int.parse(
kAppBlueLightColor)) //Colors.blue.shade400,
//Colors.blue.shade800
]),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
Icons.star,
color: Colors.yellow.shade800,
),
SizedBox(
height: 10.0,
),
Text(
lPrice,
style: TextStyle(
fontWeight: FontWeight.w500,
color: Colors.white,
),
),
SizedBox(
height: 10.0,
),
Text(
"The only reward system \n you will need ",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 22.0,
),
),
SizedBox(
height: 10.0,
),
Text(
" Improve your kid's habits and \n encourage positive behavior through rewards ",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.w400,
color: Colors.white,
),
),
SizedBox(
height: 30.0,
width: 200.0,
child: Divider(
color: Colors.white,
),
),
Text(
"FREE TRIAL 14 DAYS",
style: TextStyle(
color: Colors.white,
),
),
],
),
),
),
),
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height / 7,
child: Visibility(
child: ReusablePaymentCard(
roundCardBG1: Color(int.parse(kMcolor)),
roundCardBG2: Color(int.parse(kAppBlueLightColor)),
image: 'images/smile.png',
plan: 'FREE TRIAL',
description: 'Try for free',
descriptionColor: Color(int.parse(kMcolor)),
price: '14 Days',
monthyPrice: 0,
showDescription: true,
onClick: () async {
setState(() {
lPrice = '2000';
});
},
isCurrent: false,
isFreeVisible: true,
pId: '',
purchasedPID: 'purchasedPID',
),
visible: true,
),
),
],
)
],
),
);
}
}

class ReusablePaymentCard extends StatelessWidget {
final Color roundCardBG1, roundCardBG2;
final String image;
final String plan, planTime, description, price, currency;
final double monthyPrice;
final Color descriptionColor;
final bool showDescription;
final Function onClick;
final bool isCurrent;
final bool isFreeVisible;
final String pId, purchasedPID;

const ReusablePaymentCard(
{this.planTime,
this.image,
this.roundCardBG1,
this.roundCardBG2,
this.description,
this.descriptionColor,
this.plan,
this.price,
this.currency,
this.monthyPrice,
this.showDescription,
this.onClick,
this.isCurrent,
this.isFreeVisible,
this.pId,
this.purchasedPID});
Widget build(BuildContext context) {
print('============================deval>${purchasedPID}===>');
print('============================deval1>${pId}===>');
return GestureDetector(
onTap: onClick,
child: Stack(
alignment: Alignment.topCenter,
children: [
Center(
child: isFreeVisible
? Container(
margin:
EdgeInsets.only(top: 12.0, left: 20.0, right: 20.0),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [roundCardBG1, roundCardBG2],
),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(35.0),
topRight: Radius.circular(35.0),
),
),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 60.0,
height: 60.0,
decoration: new BoxDecoration(
color: const Color(0xff7c94b6),
image: new DecorationImage(
image: AssetImage(image),
fit: BoxFit.cover,
),
borderRadius: new BorderRadius.all(
new Radius.circular(30.0)),
border: new Border.all(
color: Colors.white,
width: 4.0,
),
),
),
SizedBox(
width: 10.0,
),
Expanded(
flex: 3,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
plan,
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.w500,
color: Colors.white,
),
),
SizedBox(
height: 5.0,
),
Visibility(
visible: showDescription,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Colors.white70,
width: 2.0,
),
borderRadius:
BorderRadius.circular(100.0),
),
child: Text(
description,
style: TextStyle(
color: descriptionColor,
fontSize: 12.0
//fontWeight: FontWeight.w900,
),
),
padding: EdgeInsets.all(2.0),
),
),
],
),
),
SizedBox(width: 50.0),
Expanded(
flex: 3,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
price,
maxLines: 1,
style: TextStyle(
fontSize: 19.0,
//fontWeight: FontWeight.bold,
color: Colors.white,
),
),
/SizedBox(
height: 5.0,
),
Text(
'PER MONTH',
style: TextStyle(color: Colors.white, fontSize: 12.0
//fontWeight: FontWeight.w900,
),
),
/
],
),
),
],
),
),
)
: Container(
decoration: BoxDecoration(
//color: Colors.white,
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Colors.white, Colors.white]),
boxShadow: [
BoxShadow(
color: Colors.grey.shade800,
offset: Offset(4.0, 4.0),
blurRadius: 15.0,
spreadRadius: 1.0,
),
],
),
width: MediaQuery.of(context).size.width,
//color: Colors.white,
child: Container(
margin:
EdgeInsets.only(top: 12.0, left: 20.0, right: 20.0),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [roundCardBG1, roundCardBG2],
),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(35.0),
topRight: Radius.circular(35.0),
),
),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 60.0,
height: 60.0,
decoration: new BoxDecoration(
color: const Color(0xff7c94b6),
image: new DecorationImage(
image: AssetImage(image),
fit: BoxFit.cover,
),
borderRadius: new BorderRadius.all(
new Radius.circular(30.0)),
border: new Border.all(
color: Colors.white,
width: 4.0,
),
),
),
SizedBox(
width: 10.0,
),
Expanded(
flex: 3,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
plan,
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.w500,
color: Colors.white,
),
),
SizedBox(
height: 5.0,
),
Visibility(
visible: showDescription,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Colors.white70,
width: 2.0,
),
borderRadius:
BorderRadius.circular(100.0),
),
child: Text(
description,
style: TextStyle(
color: descriptionColor,
fontSize: 12.0
//fontWeight: FontWeight.w900,
),
),
padding: EdgeInsets.all(2.0),
),
),
],
),
),
SizedBox(width: 50.0),
Expanded(
flex: 3,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
price,
maxLines: 1,
style: TextStyle(
fontSize: 19.0,
//fontWeight: FontWeight.bold,
color: Colors.white,
),
),
/SizedBox(
height: 5.0,
),
Text(
'PER MONTH',
style: TextStyle(color: Colors.white, fontSize: 12.0
//fontWeight: FontWeight.w900,
),
),
/
],
),
),
],
),
),
),
)),
Visibility(
visible: purchasedPID == pId,
child: Positioned(
top: 5,
right: 10,
child: Image.asset(
'images/purchased.png',
width: 40.0,
height: 40.0,
fit: BoxFit.cover,
),
),
)
],
),
);
}
}

class MyClipper extends CustomClipper {
@OverRide
Path getClip(Size size) {
var path = new Path();
path.lineTo(0.0, size.height - 40);
path.quadraticBezierTo(
size.width / 4, size.height, size.width / 2, size.height);
path.quadraticBezierTo(size.width - (size.width / 4), size.height,
size.width, size.height - 40);
path.lineTo(size.width, 0.0);
path.close();
return path;
}

@OverRide
bool shouldReclip(covariant CustomClipper oldClipper) {
return null;
}
}
`
and i am just updating one variable named 'lPrice' on click of FREE TRIAL cell
it is not updating

and error shows like this:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (30081): The following assertion was thrown building _BodyBuilder:
I/flutter (30081): Failed assertion: boolean expression must not be null
I/flutter (30081):
I/flutter (30081): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (30081): more information in this error message to help you determine and fix the underlying cause.
I/flutter (30081): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (30081): https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter (30081):
I/flutter (30081): The relevant error-causing widget was:
I/flutter (30081): Scaffold
I/flutter (30081): file:///Users/devalchauhan/Documents/WORK/PROJECTS/Karma/lib/screens/payment_screen_test.dart:17:12
I/flutter (30081):
I/flutter (30081): When the exception was thrown, this was the stack:
I/flutter (30081): #0 _RenderCustomClip.clipper= (package:flutter/src/rendering/proxy_box.dart:1266:20)
I/flutter (30081): #1 ClipPath.updateRenderObject (package:flutter/src/widgets/basic.dart:861:9)
I/flutter (30081): #2 RenderObjectElement.update (package:flutter/src/widgets/framework.dart:5517:12)
I/flutter (30081): #3 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6123:11)
I/flutter (30081): #4 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
I/flutter (30081): #5 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5647:32)
I/flutter (30081): #6 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6246:17)
I/flutter (30081): #7 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
I/flutter (30081): #8 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5647:32)
I/flutter (30081): #9 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6246:17)
I/flutter (30081): #10 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
I/flutter (30081): #11 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
I/flutter (30081): #12 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
I/flutter (30081): #13 StatelessElement.update (package:flutter/src/widgets/framework.dart:4708:5)
I/flutter (30081): #14 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
I/flutter (30081): #15 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
I/flutter (30081): #16 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
I/flutter (30081): #17 ProxyElement.update (package:flutter/src/widgets/framework.dart:4987:5)
I/flutter (30081): #18 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
I/flutter (30081): #19 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
I/flutter (30081): #20 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
I/flutter (30081): #21 ProxyElement.update (package:flutter/src/widgets/framework.dart:4987:5)
I/flutter (30081): #22 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
I/flutter (30081): #23 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5647:32)
I/flutter (30081): #24 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6246:17)
I/flutter (30081): #25 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
I/flutter (30081): #26 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
I/flutter (30081): #27 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
I/flutter (30081): #28 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
I/flutter (30081): #29 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
I/flutter (30081): #30 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
I/flutter (30081): #31 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
I/flutter (30081): #32 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
I/flutter (30081): #33 ProxyElement.update (package:flutter/src/widgets/framework.dart:4987:5)
I/flutter (30081): #34 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
I/flutter (30081): #35 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
I/flutter (30081): #36 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
I/flutter (30081): #37 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
I/flutter (30081): #38 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
I/flutter (30081): #39 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
I/flutter (30081): #40 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6125:14)
I/flutter (30081): #41 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
I/flutter (30081): #42 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
I/flutter (30081): #43 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
I/flutter (30081): #44 StatelessElement.update (package:flutter/src/widgets/framework.dart:4708:5)
I/flutter (30081): #45 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
I/flutter (30081): #46 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6125:14)
I/flutter (30081): #47 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
I/flutter (30081): #48 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
I/flutter (30081): #49 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
I/flutter (30081): #50 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
I/flutter (30081): #51 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
I/flutter (30081): #52 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
I/flutter (30081): #53 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
I/flutter (30081): #54 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
I/flutter (30081): #55 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
I/flutter (30081): #56 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
I/flutter (30081): #57 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
I/flutter (30081): #58 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
I/flutter (30081): #59 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
I/flutter (30081): #60 ProxyElement.update (package:flutter/src/widgets/framework.dart:4987:5)
I/flutter (30081): #61 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
I/flutter (30081): #62 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
I/flutter (30081): #63 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
I/flutter (30081): #64 ProxyElement.update (package:flutter/src/widgets/framework.dart:4987:5)
I/flutter (30081): #65 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
I/flutter (30081): #66 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
I/flutter (30081): #67 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
I/flutter (30081): #68 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
I/flutter (30081): #69 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
I/flutter (30081): #70 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
I/flutter (30081): #71 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
I/flutter (30081): #72 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
I/flutter (30081): #73 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
I/flutter (30081): #74 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2730:33)
I/flutter (30081): #75 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:913:20)
I/flutter (30081): #76 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:302:5)
I/flutter (30081): #77 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)
I/flutter (30081): #78 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1055:9)
I/flutter (30081): #79 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:971:5)
I/flutter (30081): #83 _invoke (dart:ui/hooks.dart:251:10)
I/flutter (30081): #84 _drawFrame (dart:ui/hooks.dart:209:3)
I/flutter (30081): (elided 3 frames from dart:async)
I/flutter (30081):
I/flutter (30081): ════════════════════════════════════════════════════════════════════════════════════════════════════

@github-actions
Copy link

github-actions bot commented Aug 5, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
r: invalid Issue is closed as not valid
Projects
None yet
Development

No branches or pull requests

2 participants