I want set value of bool v
from SharedPreferences
in flutter but getting LateInitializationError
.
here's my code:
import 'package:agl_mdd/home/home.dart';
import 'package:agl_mdd/start.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
late bool v;
bool getIsForFirstTime() {
SharedPreferences.getInstance().then((value) {
if (value.get('isBank') != null){
v = true;
}else {
v = false;
}
});
return v;
}
return MaterialApp(
title: 'App...',
theme: ThemeData(
),
debugShowCheckedModeBanner: false,
home: getIsForFirstTime() ? const Home(wholeDataList: []) : const Start(),
);
}
}
EDIT : I REALIZEm I AM STUPID.