M N*_*man 6 android firebase dart-html flutter
我正在编写一个代码,其中我正在使用 firebase 进行注册。包括个人资料图像在内的数据将被火存储。但问题是我遇到了多个无法解决的错误。我的应用程序甚至还没有运行过一次。其中一个错误是 "import:dart:html" ,我检查了所有 dart 文件,但没有找到任何未使用的 dart:html 导入。我使用 import"dart.io" 来表示术语“late File”。我也通过导入 dart:html 进行了尝试,但错误仍然相同。我还尝试删除 ProfileImage 的所有代码,但错误仍然存在。以下是有错误的 y 代码的所有文件:
\n错误
\nLaunching lib\\main.dart on sdk gphone x86 arm in debug mode...\nRunning Gradle task 'assembleDebug'...\nInvalid depfile: D:\\Noum\\Data\\Uni Data\\Codes\\Android Studio\\Flutter\\firebase_flutter_app\\.dart_tool\\flutter_build\\040ba043425f685efe2a35025cf4d63f\\kernel_snapshot.d\nInvalid depfile: D:\\Noum\\Data\\Uni Data\\Codes\\Android Studio\\Flutter\\firebase_flutter_app\\.dart_tool\\flutter_build\\040ba043425f685efe2a35025cf4d63f\\kernel_snapshot.d\n/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.1/lib/src/storage.dart:2:8: Error: Not found: 'dart:html'\nimport 'dart:html';\n ^\n/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.1/lib/src/utils.dart:2:8: Error: Not found: 'dart:html'\nimport 'dart:html';\n ^\n/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/js-0.6.3/lib/js.dart:8:1: Error: Not found: 'dart:js'\nexport 'dart:js' show allowInterop, allowInteropCaptureThis;\n^\n/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/js-0.6.3/lib/js_util.dart:8:1: Error: Not found: 'dart:js_util'\nexport 'dart:js_util';\n^\n/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.1/lib/src/auth.dart:340:25: Error: The method 'allowInterop' isn't defined for the class 'Auth'.\n - 'Auth' is from 'package:firebase/src/auth.dart' ('/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.1/lib/src/auth.dart').\nTry correcting the name to the name of an existing method, or defining a method named 'allowInterop'.\n final nextWrapper = allowInterop((firebase_interop.UserJsImpl? user) {\n ^^^^^^^^^^^^\n/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.1/lib/src/auth.dart:344:26: Error: The method 'allowInterop' isn't defined for the class 'Auth'.\n - 'Auth' is from 'package:firebase/src/auth.dart' ('/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.1/lib/src/auth.dart').\nTry correcting the name to the name of an existing method, or defining a method named 'allowInterop'.\n final errorWrapper = allowInterop((e) => changeController.addError(e));\n ^^^^^^^^^^^^\n/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.1/lib/src/auth.dart:374:9: Error: The method 'allowInterop' isn't defined for the class 'Auth'.\n - 'Auth' is from 'package:firebase/src/auth.dart' ('/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.1/lib/src/auth.dart').\nTry correcting the name to the name of an existing method, or defining a method named 'allowInterop'.\n allowInterop((firebase_interop.UserJsImpl? user) {\n ^^^^^^^^^^^^\n\n\nFAILURE: Build failed with an exception.\n\n* Where:\nScript 'C:\\src\\flutter\\flutter\\packages\\flutter_tools\\gradle\\flutter.gradle' line: 1035\n\n* What went wrong:\nExecution failed for task ':app:compileFlutterBuildDebug'.\n> Process 'command 'C:\\src\\flutter\\flutter\\bin\\flutter.bat'' finished with non-zero exit value 1\n\n* Try:\nRun 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.\n\n* Get more help at https://help.gradle.org\n\nBUILD FAILED in 43s\nException: Gradle task assembleDebug failed with exit code 1\n
Run Code Online (Sandbox Code Playgroud)\n颤振医生
\nPS C:\\Users\\Nouma> flutter doctor\nDoctor summary (to see all details, run flutter doctor -v):\n[\xe2\x88\x9a] Flutter (Channel stable, 2.2.2, on Microsoft Windows [Version 10.0.19042.1052], locale en-PK)\n[\xe2\x88\x9a] Android toolchain - develop for Android devices (Android SDK version 30.0.3)\n[\xe2\x88\x9a] Chrome - develop for the web\n[\xe2\x88\x9a] Android Studio (version 4.1.0)\n[\xe2\x88\x9a] VS Code (version 1.57.1)\n[\xe2\x88\x9a] Connected device (2 available)\n\n\xe2\x80\xa2 No issues found!\nPS C:\\Users\\Nouma>\n
Run Code Online (Sandbox Code Playgroud)\n依赖关系
\nenvironment:\n sdk: ">=2.12.0 <3.0.0"\n\ndependencies:\n flutter:\n sdk: flutter\n firebase_auth: ^2.0.0\n firebase_core: ^1.3.0\n auth_buttons: ^1.0.1+4\n cloud_firestore: ^2.3.0\n firebase_storage: ^9.0.0\n google_sign_in: ^5.0.4\n firebase_analytics: ^8.1.2\n image_picker: ^0.8.1+3\n shared_preferences: ^2.0.6\n
Run Code Online (Sandbox Code Playgroud)\nRegister.dart ,这是编写所有代码的文件
\nimport 'dart:io';\nimport 'package:cloud_firestore/cloud_firestore.dart';\nimport 'package:firebase/firebase.dart';\nimport 'package:firebase_auth/firebase_auth.dart' as route;\nimport 'package:firebase_flutter_app/ErrorAlertDialog.dart';\nimport 'package:firebase_flutter_app/StoreHome.dart';\nimport 'package:firebase_storage/firebase_storage.dart';\nimport 'package:image_picker/image_picker.dart';\nimport 'package:flutter/material.dart';\nimport 'CustomTextField.dart';\nimport 'LoadingDialog.dart';\nimport 'package:shared_preferences/shared_preferences.dart';\n\nclass Register extends StatefulWidget {\n const Register({Key? key}) : super(key: key);\n\n @override\n _RegisterState createState() => _RegisterState();\n}\n\nclass _RegisterState extends State<Register> {\n final TextEditingController _nametextEditingController=TextEditingController();\n final TextEditingController _emailtextEditingController=TextEditingController();\n final TextEditingController _passwordtextEditingController=TextEditingController();\n final TextEditingController _cPasswordEditingController=TextEditingController();\n final GlobalKey<FormState> _globalKey=GlobalKey<FormState>();\n String userImageurl="";\n late File _imagefile;\n final _picker=ImagePicker();\n static final String userID='uid';\n static final String userName='name';\n static final String userEmail='email';\n static final String userAvatar='url';\n static final String userPhotoUrl='photoUrl';\n static final String userCartList='userCart';\n SharedPreferences sharedPreferences=SharedPreferences.getInstance() as SharedPreferences;\n\n\n @override\n Widget build(BuildContext context) {\n\n double _screenwidth=MediaQuery.of(context).size.width;\n return SingleChildScrollView(\n child: Container(\n child: Column(\n mainAxisSize:MainAxisSize.max,\n children: [\n SizedBox(height: 10.0,),\n InkWell(\n onTap:(){},\n child: CircleAvatar(\n radius: _screenwidth *0.15,\n backgroundColor: Colors.white30,\n // ignore: unnecessary_null_comparison\n child: Icon(Icons.add_a_photo_outlined,size: _screenwidth *0.15,color: Colors.grey,),\n //backgroundImage: _imagefile==null ? null: FileImage(_imagefile),\n // ignore: unnecessary_null_comparison\n // child: _imagefile==null ? Icon(Icons.add_a_photo_outlined,size: _screenwidth *0.15,color: Colors.grey,)\n // :null,\n\n ),\n ),\n SizedBox(height: 8.0,),\n Form(\n key: _globalKey,\n child:Column(\n children: [\n CustomTextField(\n controller: _nametextEditingController,\n data: Icons.person,\n hintText: 'Name',\n isObsecure: false,\n ),\n CustomTextField(\n controller: _emailtextEditingController,\n data: Icons.email,\n hintText: 'Email',\n isObsecure: false,\n ),\n CustomTextField(\n controller: _passwordtextEditingController,\n data: Icons.password,\n hintText: 'Password',\n isObsecure: true,\n ),\n CustomTextField(\n controller: _cPasswordEditingController,\n data: Icons.password,\n hintText: 'Confirm Password',\n isObsecure: true,\n ),\n ],\n )\n ),\n RaisedButton(\n onPressed: ()\n {\n // uploadAndSaveImage();\n },\n color: Colors.blueGrey,\n child: Text('Sign Up',style: TextStyle(color: Colors.white30),),\n ),\n SizedBox(\n height: 30.0,\n ),\n Container(\n height: 4.0,\n width: _screenwidth* 0.8,\n color: Colors.cyan,\n ),\n SizedBox(\n height: 15.0,\n ),\n ],\n ),\n ),\n );\n }\n Future<void> _selectAndPickImage() async // ignore: unused_element\n {\n\n _imagefile = (await _picker.getImage(source: ImageSource.gallery) )as File;\n }\n\n Future<void> uploadAndSaveImage()async\n {\n // ignore: unnecessary_null_comparison\n if(_imagefile==null)\n {\n showDialog(\n context: context,\n builder:(c)\n {\n return ErrorAlertDialog(message: 'Please Select an Image');\n\n }\n );\n }\n else\n {\n _passwordtextEditingController.text==_cPasswordEditingController.text\n // ? is an 'if' condition\n //if all these are true we will upload the image\n ? _emailtextEditingController.text.isNotEmpty\n && _passwordtextEditingController.text.isNotEmpty\n && _cPasswordEditingController.text.isNotEmpty\n &&_nametextEditingController.text.isNotEmpty\n\n\n ? uploadToStorage()\n\n //this dialogue is for the upper fields if they remains somehow empty\n :displayDialog('Please fill the empty fields in form...')\n :displayDialog('Password do not match');\n\n }\n }\n displayDialog(String msg)\n {\n showDialog(context: context,\n builder: (C)\n {\n return ErrorAlertDialog(message: msg);\n }\n );\n }\n uploadToStorage()async\n {\n showDialog(\n context: context,\n builder: (c){\n return LoadingDialog(mesage: 'Authenticating, Please Wait!...',);\n }\n\n );\n //unique name to upload it to firestore,and we will use datetime sp it won't repeat again\n String imageFileName=DateTime.now().millisecondsSinceEpoch.toString();\n\n StorageReference storageReference=FirebaseStorage.instance.ref().child(imageFileName) as StorageReference;\n var uploadTask=storageReference.put(_imagefile);\n UploadTaskSnapshot taskSnapshot=await uploadTask.future;\n\n await taskSnapshot.ref.getDownloadURL().then((urlimage){\n userImageurl=urlimage as String;\n\n _registerUser();\n\n });\n\n\n\n }\n route.FirebaseAuth _auth=route.FirebaseAuth.instance;\n void _registerUser() async\n {\n route.User? userr;\n await _auth.createUserWithEmailAndPassword(\n email: _emailtextEditingController.text.trim(),\n password: _passwordtextEditingController.text.trim(),\n ).then((auth) {\n userr = auth.user!;\n }).catchError((error) {\n Navigator.pop(context);\n showDialog(\n context: context,\n builder: (c) {\n return ErrorAlertDialog(message: error.toString(),);\n }\n );\n });\n if (userr != null)\n {\n saveUserInfoToFirestore(userr!).then((value){\n Navigator.pop(context);\n //if the user registration gets successful we will send it to store home\n Route route=MaterialPageRoute(builder: (c)=>StoreHome());\n Navigator.pushReplacement(context, route);\n });\n\n }\n }\n Future saveUserInfoToFirestore(route.User firebaseUser) async\n {\n FirebaseFirestore.instance.collection('users').doc(firebaseUser.uid).set({\n 'uid':firebaseUser.uid,\n 'email':firebaseUser.email,\n 'name':_nametextEditingController.text.trim(),\n 'url':userImageurl,\n });\n await sharedPreferences.setString('uid', firebaseUser.uid);\n await sharedPreferences.setString(userEmail, firebaseUser.email.toString());\n await sharedPreferences.setString(userName, _nametextEditingController.text.trim());\n await sharedPreferences.setString(userAvatar, userImageurl);\n await sharedPreferences.setStringList(userCartList, ["garbageValue"]);\n }\n\n\n\n}\n
Run Code Online (Sandbox Code Playgroud)\nmain.dart 文件:这里我使用 dart:async 作为方法“Time”
\n//import 'package:cloud_firestore/cloud_firestore.dart';\n//import 'package:firebase/firestore.dart';\n\nimport 'dart:async'; \nimport 'package:firebase_auth/firebase_auth.dart';\nimport 'package:firebase_core/firebase_core.dart';\nimport 'package:flutter/material.dart';\n\n//import 'package:shared_preferences/shared_preferences.dart';\n\nimport 'AuthenticationScreen.dart';\nimport 'StoreHome.dart';\n\nvoid main() async{\n WidgetsFlutterBinding.ensureInitialized();\n await Firebase.initializeApp();\n //SharedPreferences sharedPreferences=SharedPreferences.getInstance() as SharedPreferences;\n //Firestore firestore=FirebaseFirestore.instance as Firestore;\n // ignore: unnecessary_statements\n\n runApp(MyApp());\n}\n\nclass MyApp extends StatelessWidget {\n // This widget is the root of your application.\n\n @override\n Widget build(BuildContext context) {\n\n return MaterialApp(\n title: 'E-Shop',\n theme: ThemeData(\n primarySwatch: Colors.blue,\n ),\n debugShowCheckedModeBanner: false,\n home: SplashScreen(),\n );\n }\n}\nclass SplashScreen extends StatefulWidget{\n @override\n State<StatefulWidget> createState() => _splashproperties();\n//=>(Fat Arrow is used to replace the braces and return)\n}\n\nclass _splashproperties extends State<SplashScreen>{\n @override\n void initState(){\n super.initState();\n displaySplash();\n }\n displaySplash(){\n FirebaseAuth auth=FirebaseAuth.instance;\n Timer(Duration(seconds: 5), () async{\n if(auth.currentUser!= null)\n {\n Route route=MaterialPageRoute(builder: (_)=>StoreHome());\n Navigator.pushReplacement(context, route);\n }\n else{\n Route route=MaterialPageRoute(builder: (_)=>AuthenticationScreen());\n Navigator.pushReplacement(context, route);\n }\n });\n }\n\n\n Widget build(BuildContext context) {\n return Material\n (\n child: Container\n (\n decoration: new BoxDecoration(\n gradient: new LinearGradient(colors:[Colors.pink,Colors.lightGreenAccent],\n begin: const FractionalOffset(0.0, 0.0),\n end: const FractionalOffset(1.0, 0.0),\n stops: [0.0,1.0],\n tileMode: TileMode.clamp,\n )\n ),\n child: Center(\n child: Column(\n mainAxisAlignment: MainAxisAlignment.center,\n children: [\n Image.asset('images/xweb.jpg'),\n SizedBox(height: 20.0),\n Text("Number One We Are!!!!!!!",style: TextStyle(color: Colors.white30),\n ),\n ],\n ),\n ),\n ),\n );\n }\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n
小智 0
尝试清理软件包并再次运行 pub get
flutter clean
./gradlew clean
flutter pub get
Run Code Online (Sandbox Code Playgroud)
如果不起作用试试这个
归档时间: |
|
查看次数: |
4138 次 |
最近记录: |