LoginSignup
0
0

More than 1 year has passed since last update.

いつの間にか、バーコードスキャンするflutter_barcode_scannerが使えなくなっていたので、barcode_scan2を使う

Posted at

はじめに

・今回の記事は、タイトルのまんまだが、バーコードスキャンに関係するパッケージのflutter_barcode_scannerが使えなくなっていたので、代替パッケージのbarcode_scan2をアプリに組み込んだという話だ。
・今から1年以上前、私がフリーターの時に作ったアプリをリリース出来ずにいた。そのアプリを手直しして公開に踏み切りました。アプリ公開する際にビルドに失敗するので、調べてみたらflutter_barcode_scannerは使用できなくなっていました😭

アプリ概要

・Google Books APIを使用した、本の検索ができるアプリケーションです。

・app

・code

パッケージ

・barcode_scan2: ^4.2.3
・freezed: ^0.14.2
・flutter_riverpod: ^0.14.0+1
・http: ^0.13.3
・state_notifier: ^0.7.0
・webview_flutter: ^4.0.2

コード

・flutter_barcode_scannerを使用したコード

Future<String> scanBarcode() async {
  String barcodeScanRes;

  try {
    barcodeScanRes = await FlutterBarcodeScanner.scanBarcode(
        '#ff6666', 'Cancel', true, ScanMode.BARCODE);
  } on PlatformException {
    barcodeScanRes = 'Failed to get platform version.';
  }

  if (!mounted) return '';

  return barcodeScanRes;
}

・barcode_scan2を使用したコード

Future<String> scanBarcode() async {
  ScanResult scanResult;

  try {
    scanResult = (await BarcodeScanner.scan()) as ScanResult;
  } on PlatformException {
    scanResult = ScanResult(
      type: ResultType.Error,
      format: BarcodeFormat.unknown,
    );
  }

  return scanResult.rawContent;
}

あまり変わらないので、学習コストは低かった。よかった😊

参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0