728x90
반응형
Before
main.dart에서 runApp부분에 viewmodel을 먼저 선언하고 있었다.
void main() {
runApp(ChangeNotifierProvider.value(value: CarModel(), child: MyApp()));
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
);
}
}
After
runApp()전에 WidgetsFlutterBinding.ensureInitialized(); 를 선언해준다.
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(ChangeNotifierProvider.value(value: CarModel(), child: MyApp()));
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
);
}
}
WidgetsFlutterBinding.ensureInitialized() 관련 문서 링크
api.flutter.dev/flutter/widgets/WidgetsFlutterBinding/ensureInitialized.html
728x90
반응형
'Flutter' 카테고리의 다른 글
[j Flutter] 사진, 아이콘 좌우반전하기 (0) | 2020.11.26 |
---|---|
[j Flutter] MediaQuery.of(context).size.width 처음 사용할때 width가 0일때 처리 (0) | 2020.11.20 |
[j Flutter] WebView 뒤로가기 (WillPopScope사용) (0) | 2020.11.13 |
[j Flutter] Webview (웹뷰)추가하기 (2) | 2020.11.13 |
[j Flutter] json 정보 가져올때 한글깨짐현상 (1) | 2020.11.12 |