Here is the error am running into
"AppClient?" not found. You need to call "Get.put(AppClient?())" or "Get.lazyPut(()=>AppClient?())"
below is the main.dart
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:keroma/controllers/popular_product_controller.dart';
import 'package:keroma/data/api/api_client.dart';
import 'package:keroma/data/repository/popular_product_repo.dart';
Future<void> init() async {
//api client
Get.lazyPut(() => ApiClient(appBaseUrl: "https://mvs.bslmeiyu.com"));
//repos
Get.lazyPut(() => PopularProductRepo(apiClient: Get.find(),appClient: Get.find() ?AppClient(),
));
//controllers
Get.lazyPut(() => PopularProductController(popularProductRepo: Get.find(),appClient:Get.find(),
));
}
class AppClient {
}
//or
class PopularProductRepo {
final ApiClient apiClient;
final AppClient appClient; //make this parameter required
PopularProductRepo({
required this.apiClient, //use the required keyword
required this.appClient, //use the required keyword
});
}
here is the dependecies.dart
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:keroma/controllers/popular_product_controller.dart';
import 'package:keroma/helper/dependencies.dart';
import 'package:keroma/initial_bindings.dart';
import 'package:keroma/pages/food/popular_food_detail.dart';
import 'package:keroma/pages/food/recommended_food_detail.dart';
import 'package:keroma/pages/home/main_food_page.dart';
import 'helper/dependencies.dart' as dep;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await dep.init();
Get.lazyPut(()=>AppClient());
runApp(const MyApp());}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
Get.find<PopularProductController>().getPopularProductList();
return GetMaterialApp(
initialBinding: InitialBinding(), // add this line
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: RecommendedFoodDetail(),
);
}
} I addressed the issue by creating a file named initial_bindings.dart in the lib folder. Then added the snippet to it, Then in main.dart, added this line("initialBinding: InitialBinding(),") into your GetMaterialApp to no avail.