'更改Notifier提供商' ISN' ta功能错误消息

发布于 2025-02-08 15:58:04 字数 230 浏览 3 评论 0原文

我正在构建一个拼写应用程序。这是给我一个错误的代码。我不知道我在做什么错。

void main() {
  runApp(ChangeNotifierProvider(create: (_) => Controller(), child: MyApp()));
}

错误消息是

'changeNotifierProvider'不是函数。

I am building a spelling app. This is the code that's giving me an error. I don't know what I'm doing wrong.

void main() {
  runApp(ChangeNotifierProvider(create: (_) => Controller(), child: MyApp()));
}

The error message is

'ChangeNotifierProvider' isn't a function.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

‖放下 2025-02-15 15:58:04

您应该使用MultileProvider

这样...

void main() {
  runApp(const MyApp());
}

和MyApp类使用MultieProvider。

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider<GetProvider>(create: (context) => GetProvider()),
      ],
      builder: (context, child) {
        return const MaterialApp(
          home: HomeScreen(),
        );
      },
    );
  }
}

you should use MultileProvider

like this...

void main() {
  runApp(const MyApp());
}

and MyApp class uses MultipleProvider.

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider<GetProvider>(create: (context) => GetProvider()),
      ],
      builder: (context, child) {
        return const MaterialApp(
          home: HomeScreen(),
        );
      },
    );
  }
}
吝吻 2025-02-15 15:58:04

您可以这样做:

class Person with ChangeNotifier {
  Person({this.name, this.age});

  final String name;
  int age;

  void increaseAge() {
    this.age++;
    notifyListeners();
  }
}

// here, you can see that the [ChangeNotifierProvider]
// is "wired up" exactly like the vanilla [Provider]
void main() {
  runApp(
    ChangeNotifierProvider(
      create: (_) => Person(name: "Yohan", age: 25),
      child: MyApp(),
    ),
  );
}

You can do Like This:

class Person with ChangeNotifier {
  Person({this.name, this.age});

  final String name;
  int age;

  void increaseAge() {
    this.age++;
    notifyListeners();
  }
}

// here, you can see that the [ChangeNotifierProvider]
// is "wired up" exactly like the vanilla [Provider]
void main() {
  runApp(
    ChangeNotifierProvider(
      create: (_) => Person(name: "Yohan", age: 25),
      child: MyApp(),
    ),
  );
}

墨落成白 2025-02-15 15:58:04
void main() {

  runApp( MyApp());

}

class MyApp extends StatelessWidget {
   MyApp({Key? key}) : super(key: key);
 
  @override
  Widget build(BuildContext context) {

    return ChangeNotifierProvider(
      create: (context) => ThemeProvider(),
      builder: (context, _) {
        final provider = Provider.of<ThemeProvider>(context);
        return MaterialApp(
          title: 'Flutter Demo',
          theme: provider.darkMode ? darkMode : lightMode,
        );
      },
    );
  }
}
void main() {

  runApp( MyApp());

}

class MyApp extends StatelessWidget {
   MyApp({Key? key}) : super(key: key);
 
  @override
  Widget build(BuildContext context) {

    return ChangeNotifierProvider(
      create: (context) => ThemeProvider(),
      builder: (context, _) {
        final provider = Provider.of<ThemeProvider>(context);
        return MaterialApp(
          title: 'Flutter Demo',
          theme: provider.darkMode ? darkMode : lightMode,
        );
      },
    );
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文