Home > database >  stateful widget error, A constant constructor can't call a non-constant super constructor of &#
stateful widget error, A constant constructor can't call a non-constant super constructor of &#

Time:01-12

here is my public git. image ps : already tried ChatMember({Key? key, this.deviceScreenType}) : super(key: key); it pop other error. enter image description here the full issue can be found in https://github.com/flutter/flutter/issues/118311. can anyone help ?

CodePudding user response:

You need to use widget clsss instead of state class. Remove params from ChatMember and use widget class.

class MyStatefulWidget extends StatefulWidget {
  final DeviceScreenType? deviceScreenType;
  const MyStatefulWidget({super.key, this.deviceScreenType});

  @override
  State<MyStatefulWidget> createState() => ChatMember();
}

class ChatMember extends State<MyStatefulWidget> {
  @override
  Widget build(BuildContext context) {

Now to access widget variable do,

Column(
  children: List.generate(
    members.length,
    (index) => MemberCard(
      member: members[index],
      deviceScreenType: widget.deviceScreenType, //this
    ),
  ),
),

Next issue is you are naming differently and it's confusing,

Your case

  • MyStatefulWidget is a widget class
  • ChatMember is state class

You need to use MyStatefulWidget like,

Container(
  width: 400,
  child: MyStatefulWidget(deviceScreenType: deviceScreenType),
),

You can check the pr

  • Related