I made todo app using getx package. I also created a login page and i want to display login page only one time but when i try to do this i a got error "HomeController" not found. You need to call "Get.put(HomeController())" or "Get.lazyPut(()=>HomeController())".
this is my binding
`
class HomeBinding implements Bindings {
@override
void dependencies() {
Get.lazyPut(() => HomeController(
taskRepository: TaskRepository(
taskProvider: TaskProvider(),
),
));
}
}
`
this is my main.dart
`
int? isViewed;
void main() async {
await GetStorage.init();
await Get.putAsync(() => StorageService().init());
WidgetsFlutterBinding.ensureInitialized();
await ScreenUtil.ensureScreenSize();
await GetStorage.init();
await Get.putAsync(() => StorageService().init());
LicenseRegistry.addLicense(() async* {
final license = await rootBundle.loadString('google_fonts/OFL.txt');
yield LicenseEntryWithLineBreaks(['google_fonts'], license);
});
SharedPreferences prefs = await SharedPreferences.getInstance();
isViewed = prefs.getInt('login');
runApp(MyApp());
}
class MyApp extends GetView<HomeController> {
const MyApp({
Key? key,
}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: Colors.transparent));
return ScreenUtilInit(
designSize: const Size(360, 800),
minTextAdapt: true,
splitScreenMode: true,
builder: (context, child) {
return GetMaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: Themes.light,
darkTheme: Themes.dark,
themeMode: ThemeMode.light,
home: isViewed != 0 ? Login() : Report(),
initialBinding: HomeBinding(),
builder: EasyLoading.init(),
);
});
}
}
`
I tried almost all method that i was familiar with .
CodePudding user response:
initialize controller into initialbinding
CodePudding user response:
Try adding HomeBinding
in getPages
array of GetMaterialApp
.
Also apply below modifications in below scope
GetMaterialApp(
// initialBinding: HomeBinding(), ====>> Remove this line
initialRoute: '/home', // ====>> Add this line
getPages: [
GetPage(
name: "/home",
page: () => const HomeScreen(),
binding: HomeBinding(),
),
// ====>> Add other pages like home
]
);