前提
ProviderScopeはエラーはなく、
StateProviderではエラーが出るのですがどうしたら良いのでしょうか?
実現したいこと
このエラーの原因は何なのか教えていただきたいです。
発生している問題・エラーメッセージ
"The function 'StateProvider' isn't defined.\nTry importing the library that defines 'StateProvider', correcting the name to the name of an existing function, or defining a function named 'StateProvider'.",
該当のソースコード
import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; void main() { runApp( const ProviderScope(child: MyApp()), ); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return const MaterialApp(home: Home()); } } final counterProvider = StateProvider((ref) => 0); ←ここの部分でエラー class Home extends ConsumerWidget { const Home({Key? key}) : super(key: key); @override Widget build(BuildContext context, WidgetRef ref) { return Scaffold( appBar: AppBar(title: const Text('Counter example')), body: Center( child: Consumer( builder: (context, ref, _) { final count = ref.watch(counterProvider); return Text('$count'); }, ), ), floatingActionButton: FloatingActionButton( onPressed: () => ref.read(counterProvider.notifier).state++, child: const Icon(Icons.add), ), ); } }
使っているパッケージのバージョンを示していただけますでしょうか?
