본문 바로가기
프레임워크/flutter

[Error]A value of type 'Null' can't be assigned to a parameter of type 'String' in a const constructor.

by seongjko 2023. 10. 9.
728x90
class CakeTimerUI extends StatefulWidget {

  final int value2;

  //const CakeTimerUI({super.key, required this.value2});

  const CakeTimerUI({Key? key, required this.value2}) : super(key: key);

  @override
  CakeTimerState createState() => CakeTimerState();
}

class CakeTimerState extends State<CakeTimerUI> {

  @override
  Widget build(BuildContext context) {
    return const Center(
      child: SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            TimerFunction(value3: widget.value2),
            Text('Value: ${widget.value2}', style: TextStyle(fontSize: 16)),
          ],
        ),
      ),
    );
  }
}

 

TimerFunction(value3: widget.value2),
Text('Value: ${widget.value2}', style: TextStyle(fontSize: 16)),

이 부분에서 자꾸 "A value of type 'Null' can't be assigned to a parameter of type 'String' in a const constructor." 이 에러가 발생한다. 

Center 앞에 붙은 const를 제거하니 에러가 사라졌다. 

 

참고

https://stackoverflow.com/questions/69182132/a-value-of-type-null-cant-be-assigned-to-a-parameter-of-type-string-in-a-co

 

A value of type 'Null' can't be assigned to a parameter of type 'String' in a const constructor

I'm unable to use questions[questionNumber] as a Text Constructor in Flutter. Errors: Evaluation of this constant expression throws an exception.dart(const_eval_throws_exception) A value of type 'N...

stackoverflow.com

 

반응형