관리 메뉴

cococo-coding

Too many positional arguments: 0 expected, but 1 found. 본문

[Flutter] Todolist/트러블슈팅

Too many positional arguments: 0 expected, but 1 found.

_dani 2024. 2. 10. 01:18

안드로이드 스튜디오로 flutter로 개발을 하는 중에 다음과 같은 오류가 났다. 

 

구글링을 해서 비슷한 질문을 발견해서 공유한다.. 아직 초짜라서 이해가 잘 안 가지만... 

nosql - 플러터 : 너무 많은 위치 인수 : 0 개가 필요하지만 1 개 발견 - 스택 오버플로 (stackoverflow.com)

 

flutter: Too many positional arguments: 0 expected, but 1 found

I've been following this NoSQL tutorial which uses BLoC. But when I paste in the code from 'fruit_event.dart' into Visual Studio Code, it gives me an error. fruit_event.dart: import 'package:equa...

stackoverflow.com

 답변을 보면 아래와 같다. 

 

생성자는 하나뿐이며 생성자는 인수 / 매개 변수를 허용하지 않습니다.
따라서 생성자에서 호출 할 수 없습니다.super(props)

그러나 코드에서 하나의 인수, 즉 수퍼 클래스의 생성자 (예 : Equatable )를 전달합니다.props
이것을 바꾸십시오.

FruitEvent([List props = const []]) : super(props);
이것으로:
FruitEvent([List props = const []]);


한국어로 번역해서 봐서 어색하긴한데, 아마 생성자에 관련된 문제인 것 같다...

 


 

오류가 난 코드를 살펴보면 다음과 같다.

 

위 코드에 child: 만 추가해줬더니 바로 해결되었다. 

 bottomNavigationBar: BottomAppBar(
          child: Row(
            children: [
              Icon(Icons.phone),
              Icon(Icons.message),
              Icon(Icons.contact_page),
            ],
          ),
        )
        )
        );
  }
}