Search code examples
androidfirebaseflutterfirebase-realtime-databasefirebase-mlkit

Flutter app does not stop installing when firebase_database depencancy is added


I am new to flutter programming and I am building a simple app with firebase ml kit and firebase database. This is a part of my university project to create a mobile wallet. Here what i am doing is scanning the credit/debit card for card details by ml vision kit and storing it in firebase databse. Scanning part is running propperly and when I add the database dependency The app is not even installing. When debugging it gives Note: C:\Users\SKYWALKER\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\firebase_core-0.2.5+1\android\src\main\java\io\flutter\plugins\firebase\core\FirebaseCorePlugin.java uses unchecked or unsafe operations.

here is my pubspec.yaml file.


environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  image_picker:
  firebase_ml_vision: ^0.9.0+3
  #firebase_database: ^2.0.2
  #firebase_core: ^0.3.4
  path_provider: ^1.4.4
  firebase_database: 1.0.3

  cupertino_icons: ^0.1.2
  charts_flutter: ^0.6.0
  rxdart: ^0.19.0
  flutter_swiper: ^1.1.4
  qr_code_scanner: ^0.0.12
  flutter_card_io:
    git:
      url: git://github.com/procedurallygenerated/flutter_card_io.git

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true

  assets:
    - assets/images/
    - assets/images/users/
    - assets/visa_logo.png
    - assets/creditcardchipsilver.png
    - assets/card_band.jpg
    - assets/card_back.jpg
    - assets/initialData.json

  fonts:
    - family: Varela
      fonts:
        - asset: assets/fonts/VarelaRound-Regular.ttf

and these are the two functions

import 'package:image_picker/image_picker.dart';
import 'package:firebase_ml_vision/firebase_ml_vision.dart';
import 'package:firebase_database/firebase_database.dart';

final databaseReference = FirebaseDatabase.instance.reference();

class AddCardPage extends StatefulWidget {
  @override
  AddCardPageState createState() => AddCardPageState();
}


class AddCardPageState extends State<AddCardPage> {
  File pickedImage;
  bool isImageLoaded = false;
  PaymentCard card1 = new PaymentCard();
  static int id;
  String encryptedCardNumber = "";
  CreditCardModel card2 = new CreditCardModel("", "", "", "");

//the create record is a testing code
  void createRecord(){
    databaseReference.child("1").set({
      'title': 'Mastering EJB',
      'description': 'Programming Guide for J2EE'
    });
    databaseReference.child("2").set({
      'title': 'Flutter in Action',
      'description': 'Complete Programming Guide to learn Flutter'
    });
  } 

  Future pickImage() async
  {
    var tempStore = await ImagePicker.pickImage(source: ImageSource.camera);
    if (mounted)
    {
      setState(() {
        pickedImage = tempStore;
        isImageLoaded = true;
      });
    }
    readText();
  }

  Future readText() async{
    String info;
    FirebaseVisionImage ourImage = FirebaseVisionImage.fromFile(pickedImage);
    TextRecognizer recognizeText = FirebaseVision.instance.textRecognizer();
    VisionText readText = await recognizeText.processImage(ourImage);
    info = readText.text;
    String text1;
    String txt;
    for(TextBlock block in readText.blocks)
    {
      for(TextLine line in block.lines)
      {
        txt = line.text;
        for(TextElement word in line.elements)
        {
          text1 = word.text;
        }
      }
    }
    //print(info);
    bool cardNumFound = false;
    bool expDateFound = false;
    for(var i = 0; i < info.length ; i++)
    {
      if(!cardNumFound)
      {
        if(info[i] == '4' || info[i] == '5')
        {
          card2.cardNumb=info.substring(i,i+19);
          cardNumFound = true;
        }
      }
      if(!expDateFound)
      {
        if(info[i] == '/')
        {
          card2.expire = info[i-2] + info[i-1] + info[i] + info[i+1] + info[i+2];
          expDateFound = true;
        }
      }
    }
    encrypt();
    print(card2.cNum);
    print(card2.expiryDate);
    createRecord();
  }
}

Here are the things I tried

  1. using an older version of firebase_database 1.0.3
  2. Tried debugging without firebase_database. that worked fine. app was doing okay.
  3. Tried to read the documentation of firebase_database and find if there are any incompatible dependencies. Did my best but no result.

Please Help. All your help would be very appriciated.


Solution

  • I don't see a firebase_auth in your pubspec.yaml file. Assuming that you have added firebase to your app ( how to add firebase to app), each user needs to be authenticated to firebase before using firebase_database ( I will recommend using cloud_firestore over firebase_database if the speed of response of database is important for you ). Use firebase_core to enable connection to multiple Firebase apps.

    Note that for the latest version of firebase_auth to work, your project needs to be AndroidX complaint (enter link description here).

    In the Project Gradle (project/app/build.gradle) add the following lines:
    
    defaultConfig {
        ...
    
        multiDexEnabled true
    }
    

    and

    dependencies {
        ...
    
        implementation 'com.android.support:multidex:1.0.3'
    }
    

    After doing this, clean cache and restart your project by clicking on File>Invalidate Caches & Restart