编译器消息:
lib/main.dart:9:62: Error: A value of type 'UserProvider' can't be assigned to a variable of type 'Widget'.
- 'UserProvider' is from 'package:user/provider/user_provider.dart' ('lib/provider/user_provider.dart').
- 'Widget' is from 'package:flutter/src/widgets/framework.dart' ('/C:/flutter/packages/flutter/lib/src/widgets/framework.dart').
runApp(ChangeNotifierProvider(builder: (_) => UserProvider.initialize(),
^
lib/main.dart:9:42: Error: The argument type 'Widget Function(BuildContext)' can't be assigned to the parameter type 'Widget Function(BuildContext, Widget)'.
- 'Widget' is from 'package:flutter/src/widgets/framework.dart' ('/C:/flutter/packages/flutter/lib/src/widgets/framework.dart').
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/flutter/packages/flutter/lib/src/widgets/framework.dart').
runApp(ChangeNotifierProvider(builder: (_) => UserProvider.initialize(),
^
Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
build failed.
FAILURE: Build failed with an exception.
* Where:
Script 'C:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 882
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\flutter\bin\flutter.bat'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 25s
Exception: Gradle task assembleDebug failed with exit code 1
我相信我有同样的问题...
这是我的代码:
void main(){
runApp(ChangeNotifierProvider(
builder: (_) => UserProvider.initialize(), // HERE IS THE PROBLEM
create: (BuildContext context) {},
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(primaryColor: Colors.deepOrange),
home: ScreensController(),
)));
希望有人可以帮助您