[flutter]Too many positional arguments: 0 allowed, but 1 found.

2021년 01월 30일 by 진아사랑해

    [flutter]Too many positional arguments: 0 allowed, but 1 found. 목차
반응형

나는 VScode를 사용하여 flutter를 연습하고 있다

 

VScode의 도움을 받아 

class ChatMessage extends StatelessWidget {

  final String txt;

  const ChatMessage({Key key, this.txt}) : super(key: key);

 

호출하는 부분은

    return Scaffold(

      appBar: AppBar(

        title: Text("Chat App"),

      ),

      body: Column(

        children: [

          Expanded(

              child: ListView(

            children: [ChatMessage("A"), ChatMessage("B")],   <- 에러 발생

 

위 제목과 같은 에러가 발생하였다

 

이를 해결한 것은 다음처럼 수정하였다

class ChatMessage extends StatelessWidget {

  final String txt;

  const ChatMessage(this.txt, {Key key}) : super(key: key);  <- 수정

 

즉 this.txt를 필수로 받도록 변경하였다.

 

 

 

 

반응형