mobile_scanner icon indicating copy to clipboard operation
mobile_scanner copied to clipboard

I need save qrcode scan

Open DiegoLimeiradaSilva opened this issue 3 years ago • 8 comments

I need save qrcode scan, example I scanned a qrcode I wanted to have the freedom to show the scanned qrcode or save it in an api

DiegoLimeiradaSilva avatar Feb 24 '22 00:02 DiegoLimeiradaSilva

I am working on this feature and will let you know when it's finished.

juliansteenbakker avatar Feb 28 '22 11:02 juliansteenbakker

Thank you for this plugin - excellent work - @DiegoLimeiradaSilva please note that adding "please" and "thank you" is much appreciated for the author's kind efforts.

daveshirman avatar Mar 01 '22 21:03 daveshirman

I asked a question and forgot about the ? but thank you very much for your attention. a great plugin

DiegoLimeiradaSilva avatar Mar 01 '22 22:03 DiegoLimeiradaSilva

I've implemented basic local saving facility using SharedPreferences. Using which U can store the qr data locally and retrive it whenever we want.

import 'dart:convert';

class Todo {
  String? description;
  // String ?currentTime;

  Todo(this.description);
  // Todo(this.description, this.currentTime);

  Todo.fromJson(Map<String, dynamic> json) {
    description = json["description"];
    // currentTime = json["date-time"];
  }

  static Map<String, dynamic> toJson(Todo todo) =>
      {'description': todo.description};
  // {'description': todo.description, "date-time": todo.currentTime};

  static String encode(List<Todo> todos) => json.encode(
        todos.map<Map<String, dynamic>>((todo) => Todo.toJson(todo)).toList(),
      );

  static List<Todo> decode(String todos) =>
      (json.decode(todos) as List<dynamic>)
          .map<Todo>((item) => Todo.fromJson(item))
          .toList();
}

jayesh-maiyani avatar May 14 '22 05:05 jayesh-maiyani

this is what I'm doing when saving the info from qr

void _persistPreference(String text) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    if (!text.toLowerCase().contains('not yet scanned')) {
      if (prefs.containsKey('history')) {
        String? hist = prefs.getString('history');
        List<Todo> todoCurrent = Todo.decode(hist!);
        globals.todos = todoCurrent;
        globals.todos.add(Todo(text));
        // globals.todos.add(Todo(text, DateTime.now().toString()));
        prefs.setString('history', Todo.encode(globals.todos));
      } else {
        globals.todos.add(Todo(text));
        // globals.todos.add(Todo(text, DateTime.now().toString()));

        prefs.setString('history', Todo.encode(globals.todos));
      }
    }
  }

and this function presents it on other screen as history

SharedPreferences? prefs;
  Future<void> initializePreference() async {
    prefs = await SharedPreferences.getInstance();
    if (prefs!.containsKey('history')) {
      String? hist = prefs?.getString('history');
      List<Todo> todoCurrent = Todo.decode(hist!);
      globals.todos = todoCurrent;
    }
  }

jayesh-maiyani avatar May 14 '22 05:05 jayesh-maiyani

é isso que estou fazendo ao salvar as informações do qr

void _persistPreference(String text) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    if (!text.toLowerCase().contains('not yet scanned')) {
      if (prefs.containsKey('history')) {
        String? hist = prefs.getString('history');
        List<Todo> todoCurrent = Todo.decode(hist!);
        globals.todos = todoCurrent;
        globals.todos.add(Todo(text));
        // globals.todos.add(Todo(text, DateTime.now().toString()));
        prefs.setString('history', Todo.encode(globals.todos));
      } else {
        globals.todos.add(Todo(text));
        // globals.todos.add(Todo(text, DateTime.now().toString()));

        prefs.setString('history', Todo.encode(globals.todos));
      }
    }
  }

e esta função o apresenta em outra tela como histórico

SharedPreferences? prefs;
  Future<void> initializePreference() async {
    prefs = await SharedPreferences.getInstance();
    if (prefs!.containsKey('history')) {
      String? hist = prefs?.getString('history');
      List<Todo> todoCurrent = Todo.decode(hist!);
      globals.todos = todoCurrent;
    }
  }

I need to save the image used for the qrcode reading process

DiegoLimeiradaSilva avatar May 15 '22 01:05 DiegoLimeiradaSilva

Okay. I thought the other way. Lets see what can be done.

jayesh-maiyani avatar May 15 '22 03:05 jayesh-maiyani

Hi! Do we have any update of feature save image QR? Please up your answer if have any update Thanks

LevisLuong avatar Jun 24 '22 04:06 LevisLuong

With version 3.0.0-beta.4 you can retrieve the scanned image like so: https://github.com/juliansteenbakker/mobile_scanner/blob/master/example/lib/barcode_scanner_returning_image.dart

Please note that this is still a beta so there can be breaking changes in the near future

juliansteenbakker avatar Dec 13 '22 15:12 juliansteenbakker