相关疑难解决方法(0)

Flutter Getx - 找不到“Xxx”。你需要调用“Get.put(Xxx())”——但我已经调用了 Get.put(Xxx())

我有这个全局绑定类来初始化一些服务,我需要立即初始化它:

import 'package:get/get.dart';
import 'package:vepo/data/data_provider/local_data_provider.dart';
import 'package:vepo/data/data_source/local_data_source.dart';

import 'services/authentication_service.dart';

class GlobalBindings extends Bindings {
  final LocalDataProvider _localDataProvider = LocalDataProvider();
  @override
  void dependencies() {
    Get.put<AuthenticationService>(AuthenticationService(), permanent: true);
    Get.put<LocalDataProvider>(_localDataProvider, permanent: true);
    Get.put<LocalDataSource>(LocalDataSource(_localDataProvider),
        permanent: true);
  }
}
Run Code Online (Sandbox Code Playgroud)

这是在我的初始绑定中:

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: 'Vepo',
      initialRoute: AppPages.INITIAL,
      initialBinding: GlobalBindings(),
      transitionDuration: const Duration(milliseconds: 500),
      defaultTransition: Transition.rightToLeft,
      getPages: AppPages.routes,
      home: Root(),
      theme: homeTheme,
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

然后在类构造函数中,我尝试“找到”它:

class UserLocalRepository extends VpService implements IUserLocalRepository {
  UserLocalRepository() {
    localDataSource = …
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-get getx

5
推荐指数
1
解决办法
6169
查看次数

标签 统计

dart ×1

flutter ×1

flutter-get ×1

getx ×1