尝试建立APK和这些错误发生:Flutter Firebase.app(应用程序名称)错误,任务“:app:compileFlutterBuildDebug”执行失败

np8igboo  于 2022-12-30  发布在  Flutter
关注(0)|答案(1)|浏览(127)

我收到这些错误

This is one of many:
1.Try correcting the name to the name of an existing getter, or defining a getter or field named 'Firebase'.
        FirebaseFirestorePlatform.instanceFor(app: Firebase.app(appName));
2.This error comes at the end:
Execution failed for task ':app:compileFlutterBuildDebug'.

我试图从firebase获得经度和纬度,并检索了一段时间,然后我试图建立应用程序的APK,不幸的是,在这样做的时候出现了上述错误,现在我甚至不能在模拟器上运行我的应用程序。
我尝试了每件事,我可以找到网上和论坛,但没有为我工作,我试着从我的应用程序中完全删除firebase,它工作正常,但只要我把firebase的代码再次发生同样的错误,我不明白,如果问题是与插件或其他任何东西,但问题只开始发生后,我试图建立一个APK。
这是我正在使用的代码:
Map屏幕2:

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'dart:async';
import 'package:google_maps_flutter/google_maps_flutter.dart';

import 'SearchScreen.dart';

class MapScreen2 extends StatefulWidget {
  const MapScreen2({Key? key}) : super(key: key);

  @override
  State<MapScreen2> createState() => _MapScreen2State();
}

class _MapScreen2State extends State<MapScreen2> {
  static const _initialCameraPosition = CameraPosition(
    target: LatLng(24.923816, 67.098588),
    zoom: 11.5,
  );

  Completer <GoogleMapController> _googleMapController= Completer();

  Map<MarkerId, Marker> markers = <MarkerId, Marker>{};
  void initMarkers(specify, specifyID) async{
    var markerIDVal = specifyID;
    final MarkerId markerId = MarkerId(markerIDVal);
    final Marker marker = Marker(
        markerId: markerId,
        position: LatLng(specify['Latitude'], specify['Longitude']),
        infoWindow: InfoWindow(title: 'Data'),
        icon: BitmapDescriptor.defaultMarker
    );
    setState(() {
      markers[markerId]=marker;
    });
  }

  getMarkerData()async{
    FirebaseFirestore.instance.collection('Location').get().then((myMockData){
      if(myMockData.docs.isNotEmpty){
        for (int i=0; i<myMockData.docs.length;i++){
          initMarkers(myMockData.docs[i].data(), myMockData.docs[i].id);
        }
      }
    });
  }

  Future<Position> getUserCurrentLocation() async{
    await Geolocator.requestPermission().then((value){
    }).onError((error, stackTrace){
      print("error"+error.toString());
    });
    return await Geolocator.getCurrentPosition();
  }

  @override
  void initState(){
    getMarkerData();
    super.initState();
    // loadData();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          onPressed: (){
            Navigator.pop(context);
          },
          icon: CircleAvatar(
            backgroundColor: Color.fromRGBO(26, 26, 26, 1),
            child: const Icon(
              Icons.arrow_back,
              color: Color.fromRGBO(230, 230, 230, 1),
            ),
          ),
        ),
        elevation: 0,
        centerTitle: true,
        backgroundColor: Color.fromRGBO(26, 26, 26, 1),
        foregroundColor: Color.fromRGBO(230, 230, 230, 1),
        titleTextStyle: TextStyle(
            fontWeight: FontWeight.w500, fontSize: 26
        ),
        title: const Text("Pothole Map"),
      ),
      body: Stack(
        children: [
          SizedBox(
            width: double.infinity,
            height: 800,
            child: GoogleMap(
              zoomControlsEnabled: false,
              myLocationEnabled: true,
              initialCameraPosition: _initialCameraPosition,
              markers:Set<Marker>.of(markers.values),
              //markers: Set<Marker>.of(_markers),
              onMapCreated: (GoogleMapController controller) {
                _googleMapController.complete(controller);
              },
            ),
          ),
          SizedBox(
            width: double.infinity,
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    clipBehavior: Clip.antiAlias,
                    decoration: BoxDecoration(
                      color: Colors.white,
                    ),
                    child: Column(
                      children: [
                        TextField(
                          onTap: (){
                            Navigator.push(context, MaterialPageRoute(builder: (context)=>SearchScreen(),
                              fullscreenDialog: true,
                            ),
                            );
                          },
                          decoration: InputDecoration(
                            hintText: 'Where To?',
                            hintStyle: TextStyle(color: Color.fromRGBO(191, 191, 191, 1),fontWeight: FontWeight.w500, fontSize: 22),
                            border: InputBorder.none,
                            filled: true,
                            fillColor: Color.fromRGBO(26, 26, 26, 1),
                          ),
                          autofocus: false,
                          showCursor: false,
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        backgroundColor: Color.fromRGBO(26, 26, 26, 1),
        foregroundColor: Color.fromRGBO(230, 230, 230, 1),
        onPressed: () async{
          getUserCurrentLocation().then((value)async{
            CameraPosition cameraPosition=CameraPosition(
                zoom: 14,
                target: LatLng(value.latitude, value.longitude)
            );
            final GoogleMapController controller= await _googleMapController.future;
            controller.animateCamera(CameraUpdate.newCameraPosition(cameraPosition));
            setState(() {});
          });
        },
        child: const Icon(Icons.navigation),
      ),
    );
  }
}

主要:

import 'package:firebase_core/firebase_core.dart%20%20';
import 'package:flutter/material.dart';
import 'MapScreen2.dart';
import 'SearchScreen.dart';

void main() async{
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Google Map',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MainScreen(),
    );
  }
}

class MainScreen extends StatefulWidget {
  const MainScreen({super.key});

  @override
  State<MainScreen> createState() => _MainScreenState();
}

class _MainScreenState extends State<MainScreen> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        backgroundColor: Color.fromRGBO(26, 26, 26, 1),
        foregroundColor: Color.fromRGBO(230, 230, 230, 1),
        titleTextStyle: TextStyle(
            fontWeight: FontWeight.w500, fontSize: 26
        ),
        title: const Text("Pothole Map"),
      ),
      body: Stack(
        children: [
          SizedBox(
            width: double.infinity,
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    clipBehavior: Clip.antiAlias,
                    decoration: BoxDecoration(
                      color: Colors.white,
                    ),
                    child: Column(
                      children: [
                        TextField(
                          onTap: (){
                            Navigator.push(context, MaterialPageRoute(builder: (context)=>MapScreen2(),
                              fullscreenDialog: true,
                            ),
                            );
                          },
                          decoration: InputDecoration(
                            hintText: 'Map',
                            hintStyle: TextStyle(color: Colors.white,fontWeight: FontWeight.w500, fontSize: 22),
                            border: InputBorder.none,
                            filled: true,
                            fillColor: Color.fromRGBO(26, 26, 26, 1),
                          ),
                          autofocus: false,
                          showCursor: false,
                        ),
                        SizedBox(height: 10,),
                        TextField(
                          onTap: (){
                            Navigator.push(context, MaterialPageRoute(builder: (context)=>SearchScreen(),
                              fullscreenDialog: true,
                            ),
                            );
                          },
                          decoration: InputDecoration(
                            hintText: 'Where To?',
                            hintStyle: TextStyle(color:Color.fromRGBO(191, 191, 191, 1),fontWeight: FontWeight.w500, fontSize: 22),
                            border: InputBorder.none,
                            filled: true,
                            fillColor: Color.fromRGBO(26, 26, 26, 1),
                          ),
                          autofocus: false,
                          showCursor: false,
                        ),
                        SizedBox(height: 10,),
                        TextField(
                          onTap: (){
                          },
                          decoration: InputDecoration(
                            hintText: 'Feedback',
                            hintStyle: TextStyle(color: Color.fromRGBO(191, 191, 191, 1),fontWeight: FontWeight.w500, fontSize: 22),
                            border: InputBorder.none,
                            filled: true,
                            fillColor: Color.fromRGBO(26, 26, 26, 1),
                          ),
                          autofocus: false,
                          showCursor: false,
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}

pubsec.yaml:

name: new_final_app
description: A new Flutter project.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: '>=2.18.5 <3.0.0'

dependencies:
  flutter:
    sdk: flutter

  dio: ^4.0.0
  flutter_polyline_points: ^1.0.0
  google_maps_flutter: ^2.0.2
  cupertino_icons: ^1.0.2
  geolocator: ^9.0.2
  geocoding: ^2.0.4
  http:
  uuid: ^3.0.5
  google_place: ^0.4.7
  flutter_spinkit: ^5.1.0
  flutter_launcher_icons: ^0.11.0
  cloud_firestore: ^4.3.0
  firebase_database: ^10.0.8
  firebase_core: ^2.4.0
  firebase_auth: ^4.2.3

flutter_icons:
  android: true
  ios: true
  image_path: "assets/image.jpeg"

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.0

flutter:
  assets:
    - assets/pothole.png
  uses-material-design: true
ecr0jaav

ecr0jaav1#

所以代码对我起作用了,经过几次修改首先通过Firebase CLI配置你的Firebase,并使用NPM选项配置“Firebase CLI”,它对我起作用了,之后,如果你以前配置你的应用程序通过android选项只比删除所有的配置,如json文件firebase和所有其他依赖项以及.我希望这个问题和答案帮助任何人谁是面临的问题.我会提供所有帮助我的链接,
如何安装firebase cli:https://firebase.google.com/docs/cli#setup_update_cli
关于如何安装firebase cli的视频指南:https://www.youtube.com/watch?v=O7mpIlF2L7w&t=474s&ab_channel=FlutterForce
并尝试使用vscode,而使用“flutterfire配置”,因为我不知道为什么,但这个命令没有为我在android studio工作.

相关问题