본문 바로가기

개발 홀로서기/Flutter (Dart)

[flutter] The name 'MyApp' isn't a class. Try correcting the name to match an existing class.

 

The name 'MyApp' isn't a class.
Try correcting the name to match an existing class.

 

강의를 보며 따라하다가 갑자기 이런 에러가 나옴

근데 또 실행은 되고 디버깅도 잘 되는데.. 되는게 이상함..

 

해결방법은

기존 클래스와 일치하도록 이름을 수정하라는 것인데..

더블클릭해서 문제의 문단으로 가게 되면

widget_test.dart 파일에

await tester.pumpWidget(const MyApp());

이 부분으로 가게된다.

 

이 부분의 MyApp() 클래스가 main.dart에서 호출되는

클래스와 이름이 달라서이다. 동일하게 맞춰 주면 문제가 사라진다.

 

 "const MyApp()"을 첫 번째 Widget 클래스와 동일한 이름으로 변경합니다.

main.dart 파일의 기본 함수 내부에 있는 runApp 함수에서 인스턴스화한 클래스입니다.

 

출처 : https://stackoverflow.com/questions/69527724/the-name-myapp-isnt-a-class-try-correcting-the-name-to-match-an-existing-cla

'개발 홀로서기 > Flutter (Dart)' 카테고리의 다른 글

VS Code Settings, Constant 자동 설정  (0) 2023.07.09