-1
import 'package:flutter/material.dart';
import 'login_page.dart';
import 'sign_in.dart';
import 'package:image_picker/image_picker.dart';
import 'package:firebase_ml_vision/firebase_ml_vision.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class FirstScreen extends StatelessWidget {
  var myDatabase = Firestore.instance;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Center(child: Text('IT Interns are the best!!')),
        ),
        backgroundColor: Colors.white,
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'Welcome to Krea\'s Official App!',
              textAlign: TextAlign.center,
              style: TextStyle(
                  fontWeight: FontWeight.w800,
                  fontSize: 40.0,
                  color: Colors.black),
            ),
            SizedBox(height: 30.0),
            Container(
              child: Image.asset('assets/krea.png'),
            ),
            SizedBox(
              height: 50.0,
              width: 250.0,
              child: Divider(color: Colors.blueAccent),
            ),
            Icon(
              Icons.face,
              size: 120,
            ),
            Text(
              'Akshay Jain',
              style: TextStyle(
                fontSize: 40.0,
                color: Colors.black,
                fontWeight: FontWeight.bold,
              ),
            ),
            Text(
              'Krea_StudentLife_Level_100',
              style: TextStyle(
                fontSize: 18.0,
                color: Colors.black,
                fontWeight: FontWeight.normal,
                letterSpacing: 1.0,
              ),
            ),
            SizedBox(height: 20.0),
            RaisedButton(
                onPressed: () {
                  ImagePicker.getImage(source: ImageSource.camera)
                      .then((photo) {
                    BarcodeDetector detector = FirebaseVision.instance
                        .barcodeDetector(BarcodeDetectorOptions(
                            barcodeFormats: BarcodeFormat.qrCode));
                    detector
                        .detectInImage(FirebaseVisionImage.fromFile(photo))
                        .then((barcodes) {
                      if (barcodes.length > 0) {
                        var barcode = barcodes[0]; // Pick first barcode

                        myDatabase.collection("qr_codes").add({
                          "raw_data": barcode.rawValue,
                          "time": new DateTime.now().millisecondsSinceEpoch
                        }).then((_) {
                          print("One document added.");
                        });

                        showDialog(
                            context: context,
                            builder: (context) {
                              return new AlertDialog(
                                title: new Text("QR Code Contents"),
                                content: new Text(barcode.rawValue),
                                actions: <Widget>[
                                  new FlatButton(
                                      onPressed: () {
                                        Navigator.of(context).pop();
                                      },
                                      child: new Text("OK"))
                                ],
                              );
                            });
                      }
                    });
                  });
                },
                child: new Text("Capture QR Code")),
            FloatingActionButton.extended(
              onPressed: () {
                signOutGoogle();
                Navigator.of(context).pushAndRemoveUntil(
                    MaterialPageRoute(builder: (context) {
                  return LoginPage();
                }), ModalRoute.withName('/'));
              },
              backgroundColor: Colors.blue,
              icon: Icon(Icons.lock),
              label: Text('Sign Out'),
            ),
          ],
        ),
      ),
    );
  }
}

The error we are getting is that on line 62 it says that Instance member 'getImage' can't be accessed using static access. which is where the whole code fails. It seems to be a package issue but because of the getImage line, the QR codes are not being processed.

Muldec
  • 4,641
  • 1
  • 25
  • 44
  • 1
    Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Jul 10 '20 at 06:54
  • Please post the full error or stacktrace. Check out https://stackoverflow.com/help/how-to-ask – Joe W Jul 10 '20 at 08:07

2 Answers2

2

First you need to get instance of ImagePicker():

class FirstScreen extends StatelessWidget {
  var picker = ImagePicker();

And then in your button click use this created instance:

picker.getImage(source: ImageSource.camera).then((photo) {});
1

The error message is self explanatory. Replace ImagePicker.getImage by an instance call instead of a static class call like

var picker = ImagePicker;
picker.getImage(...)
Muldec
  • 4,641
  • 1
  • 25
  • 44