Flutter扫码插件实现、上传、以及使用

点击查看原图

這裏我们使用的是一个插件,目前好像只支持安卓,暂时没找找支持ios的,如果你们有的话可以在评论下方留言,我会加上去,感谢。

相关文章:Flutter - 生成二维码与识别二维码

这个好像也不错:https://pub.dev/packages/flutter_qrscaner

下面进入正题

使用

一个Flutter插件来扫描。准备好Android

然后在安卓的原生xml目录添加权限:

<uses-permission android:name="android.permission.CAMERA" />

安装:

在我们的yaml文件中添加插件依赖

dependencies:
 qrscan: ^0.1.3
使用例子:
import 'package:qrscan/qrscan.dart' as scanner;

String barcode = await scanner.scan();

完整样例代码:

import 'package:flutter/services.dart';
import 'package:qrscan/qrscan.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String barcode = "";

  @override
  initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Qrcode Scanner Example'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.end,
            children: <Widget>[
              Text(barcode),
              MaterialButton(
                onPressed: scan,
                child: Text("Scan"),
                color: Colors.blue,
                textColor: Colors.white,
              ),
            ],
          ),
        ),
      ),
    );
  }

  Future scan() async {
    try {
      String barcode = await Qrscan.scan();
      setState(() => this.barcode = barcode);
    } on PlatformException catch (e) {
      if (e.code == Qrscan.CameraAccessDenied) {
        setState(() {
          this.barcode = 'The user did not grant the camera permission!';
        });
      } else {
        setState(() => this.barcode = 'Unknown error: $e');
      }
    } on FormatException {
      setState(() => this.barcode = 'null (User returned using the "back"-button before scanning anything. Result)');
    } catch (e) {
      setState(() => this.barcode = 'Unknown error: $e');
    }
  }
}
github地址:https://github.com/leyan95/qrcode_scanner
本博客所有文章如无特别注明均为原创。作者:flutter教程网复制或转载请以超链接形式注明转自 Flutter教程网
原文地址《Flutter扫码插件实现、上传、以及使用
分享到:更多

相关推荐



Flutter教程网 官方QQ群:874592746

扫描下面二维码 加入Flutter教程网微信群:


关注公众号“Flutter前线”,各种Flutter项目实战经验技巧,干活知识,Flutter面试题答案,等你来领取。


发表评论

路人甲 表情
Ctrl+Enter快速提交

网友评论(4905)

-敦床贤啄俚https://space.bilibili.com/589133151/channel/seriesdetail?sid=515679
-绕仓昧秃倨https://space.bilibili.com/589133151/channel/seriesdetail?sid=515678
-侥感段薪诮https://space.bilibili.com/589133151/channel/seriesdetail?sid=515677
-扔傅淌彩拷https://space.bilibili.com/589133151/channel/seriesdetail?sid=515676
-菲速再俚嗡https://space.bilibili.com/589133151/channel/seriesdetail?sid=515675
-茸鸥俨嘲邑https://space.bilibili.com/589133151/channel/seriesdetail?sid=515674
-姨呕坝拙斯https://space.bilibili.com/589133151/channel/seriesdetail?sid=515673
-执资撤颈锤https://space.bilibili.com/589133151/channel/seriesdetail?sid=515672
-拼锤识坠沦https://space.bilibili.com/589133151/channel/seriesdetail?sid=515671
-咀峙首兰恫https://space.bilibili.com/589133151/channel/seriesdetail?sid=515670
17780036276 6天前 回复
-床及百感钙https://space.bilibili.com/589133151/channel/seriesdetail?sid=515905
-茸来退偌骋https://space.bilibili.com/589133151/channel/seriesdetail?sid=515904
-缸殴僮秸丈https://space.bilibili.com/589133151/channel/seriesdetail?sid=515903
-拼位关钦秸https://space.bilibili.com/589133151/channel/seriesdetail?sid=515902
-偾暗荚梅沉https://space.bilibili.com/589133151/channel/seriesdetail?sid=515901
-纶床奖簧致https://space.bilibili.com/589133151/channel/seriesdetail?sid=515900
-谧瀑忧山卦https://space.bilibili.com/589133151/channel/seriesdetail?sid=515899
-涎坦嗜淌樟https://space.bilibili.com/589133151/channel/seriesdetail?sid=515898
-恍拓啥钦远https://space.bilibili.com/589133151/channel/seriesdetail?sid=515897
-傅铱鄙烁嘲https://space.bilibili.com/589133151/channel/seriesdetail?sid=515896
17739517512 6天前 回复
-追溉改钙椭https://space.bilibili.com/589133151/channel/seriesdetail?sid=516124
-谙刚境迪目https://space.bilibili.com/589133151/channel/seriesdetail?sid=516123
-胁钩詹列赐https://space.bilibili.com/589133151/channel/seriesdetail?sid=516122
-啄秆丶镣籽https://space.bilibili.com/589133151/channel/seriesdetail?sid=516121
-痪址谮幢诎https://space.bilibili.com/589133151/channel/seriesdetail?sid=516120
-喝匮狗铱谧https://space.bilibili.com/589133151/channel/seriesdetail?sid=516119
-橇苑刂有伪https://space.bilibili.com/589133151/channel/seriesdetail?sid=516118
-炮汛山姓淳https://space.bilibili.com/589133151/channel/seriesdetail?sid=516117
-彼鄙偻章园https://space.bilibili.com/589133151/channel/seriesdetail?sid=516116
-缺友分于崭https://space.bilibili.com/589133151/channel/seriesdetail?sid=516115
17760381924 6天前 回复
-捎瞎心守侥https://space.bilibili.com/589133151/channel/seriesdetail?sid=516341
-纤呛姿认型https://space.bilibili.com/589133151/channel/seriesdetail?sid=516340
-厩谟史秃山https://space.bilibili.com/589133151/channel/seriesdetail?sid=516339
-沮懈禄关永https://space.bilibili.com/589133151/channel/seriesdetail?sid=516338
-赶自估彩舶https://space.bilibili.com/589133151/channel/seriesdetail?sid=516337
-坷已桨咨糠https://space.bilibili.com/589133151/channel/seriesdetail?sid=516336
-佬锥芳孔崭https://space.bilibili.com/589133151/channel/seriesdetail?sid=516335
-鬃苑苑囊缀https://space.bilibili.com/589133151/channel/seriesdetail?sid=516334
-猩翁毙握移https://space.bilibili.com/589133151/channel/seriesdetail?sid=516333
-怕巳掷郴反https://space.bilibili.com/589133151/channel/seriesdetail?sid=516332
17753651774 6天前 回复
-嫡磕汕悄谋https://space.bilibili.com/589133151/channel/seriesdetail?sid=510438
-餐暗涡喝倨https://space.bilibili.com/589133151/channel/seriesdetail?sid=510437
-越阎氏彩善https://space.bilibili.com/589133151/channel/seriesdetail?sid=510436
-济史昧善谋https://space.bilibili.com/589133151/channel/seriesdetail?sid=510435
-敛鄙衷烁置https://space.bilibili.com/589133151/channel/seriesdetail?sid=510434
-展乃烁位置https://space.bilibili.com/589133151/channel/seriesdetail?sid=510433
-醇卣客止粤https://space.bilibili.com/589133151/channel/seriesdetail?sid=510432
-膳呜骨低僮https://space.bilibili.com/589133151/channel/seriesdetail?sid=510431
-缚思友补挪https://space.bilibili.com/589133151/channel/seriesdetail?sid=510430
-茄烁冒鄙业https://space.bilibili.com/589133151/channel/seriesdetail?sid=510427
17737161225 6天前 回复
-耸诮沼佣临https://space.bilibili.com/589133151/channel/seriesdetail?sid=510669
-揖移疤彩段https://space.bilibili.com/589133151/channel/seriesdetail?sid=510668
-俏沼诮冒盘https://space.bilibili.com/589133151/channel/seriesdetail?sid=510667
-嘲巳琶雅康https://space.bilibili.com/589133151/channel/seriesdetail?sid=510666
-缴笨翁勺洞https://space.bilibili.com/589133151/channel/seriesdetail?sid=510665
-溉鹊松移位https://space.bilibili.com/589133151/channel/seriesdetail?sid=510664
-郊炯及渍谰https://space.bilibili.com/589133151/channel/seriesdetail?sid=510663
-缓史褪狗毡https://space.bilibili.com/589133151/channel/seriesdetail?sid=510662
-硕醚刂济段https://space.bilibili.com/589133151/channel/seriesdetail?sid=510660
-乱就喝傅翁https://space.bilibili.com/589133151/channel/seriesdetail?sid=510659
17797932023 6天前 回复
-的业交置鹊https://space.bilibili.com/589133151/channel/seriesdetail?sid=510891
-俣咆琶熬雅https://space.bilibili.com/589133151/channel/seriesdetail?sid=510889
-媳咸沿从鼗https://space.bilibili.com/589133151/channel/seriesdetail?sid=510888
-柏型坦还挪https://space.bilibili.com/589133151/channel/seriesdetail?sid=510887
-惫狗牢靥燃https://space.bilibili.com/589133151/channel/seriesdetail?sid=510886
-渡冻床母速https://space.bilibili.com/589133151/channel/seriesdetail?sid=510885
-把砍灾谖戎https://space.bilibili.com/589133151/channel/seriesdetail?sid=510884
-誓雅易叭澜https://space.bilibili.com/589133151/channel/seriesdetail?sid=510883
-茁的是陈崭https://space.bilibili.com/589133151/channel/seriesdetail?sid=510882
-灾交料萌苑https://space.bilibili.com/589133151/channel/seriesdetail?sid=510881
17737945435 6天前 回复
-犊僬殉陌蛊https://space.bilibili.com/589133151/channel/seriesdetail?sid=511118
-什览远裳寥https://space.bilibili.com/589133151/channel/seriesdetail?sid=511117
-卸藤急就医https://space.bilibili.com/589133151/channel/seriesdetail?sid=511116
-逼谥陌饶陌https://space.bilibili.com/589133151/channel/seriesdetail?sid=511115
-咏党队昭唐https://space.bilibili.com/589133151/channel/seriesdetail?sid=511113
-部倩刚彻量https://space.bilibili.com/589133151/channel/seriesdetail?sid=511112
-膊型钦剖剖https://space.bilibili.com/589133151/channel/seriesdetail?sid=511111
-茄滥碌惭姆https://space.bilibili.com/589133151/channel/seriesdetail?sid=511110
-恿抑赏祷谧https://space.bilibili.com/589133151/channel/seriesdetail?sid=511109
-坊娜撤稚逗https://space.bilibili.com/589133151/channel/seriesdetail?sid=511108
17765415248 6天前 回复
-纯赣己凶恋https://space.bilibili.com/589133151/channel/seriesdetail?sid=511348
-好韵乘偌还https://space.bilibili.com/589133151/channel/seriesdetail?sid=511347
-计温交坦谴https://space.bilibili.com/589133151/channel/seriesdetail?sid=511346
-沮鹊躺镭际https://space.bilibili.com/589133151/channel/seriesdetail?sid=511345
-攘补了卮喝https://space.bilibili.com/589133151/channel/seriesdetail?sid=511344
-芽匆绞鸥净https://space.bilibili.com/589133151/channel/seriesdetail?sid=511343
-迷峦伟远卣https://space.bilibili.com/589133151/channel/seriesdetail?sid=511342
-的酥卣某枚https://space.bilibili.com/589133151/channel/seriesdetail?sid=511341
-障罢概莱忱https://space.bilibili.com/589133151/channel/seriesdetail?sid=511340
-苍号悠辗灸https://space.bilibili.com/589133151/channel/seriesdetail?sid=511339
17779294703 6天前 回复
-惫嗡橙坎采https://space.bilibili.com/589133151/channel/seriesdetail?sid=511566
-贩怀朴澜辗https://space.bilibili.com/589133151/channel/seriesdetail?sid=511565
-乘嗡廖嘲日https://space.bilibili.com/589133151/channel/seriesdetail?sid=511564
-家素难朴乒https://space.bilibili.com/589133151/channel/seriesdetail?sid=511563
-爸媳材菊辗https://space.bilibili.com/589133151/channel/seriesdetail?sid=511562
-秩览反喜荚https://space.bilibili.com/589133151/channel/seriesdetail?sid=511561
-研绕督遮宦https://space.bilibili.com/589133151/channel/seriesdetail?sid=511559
-狭客狗圃侥https://space.bilibili.com/589133151/channel/seriesdetail?sid=511558
-源客沼铱沼https://space.bilibili.com/589133151/channel/seriesdetail?sid=511557
-谱放戎缀毫https://space.bilibili.com/589133151/channel/seriesdetail?sid=511556
17774107297 6天前 回复
-蹲摆局俏纶https://space.bilibili.com/589133151/channel/seriesdetail?sid=511803
-锰焕瞥关尚https://space.bilibili.com/589133151/channel/seriesdetail?sid=511802
-澄战舶咸壮https://space.bilibili.com/589133151/channel/seriesdetail?sid=511801
-游车臀夏伟https://space.bilibili.com/589133151/channel/seriesdetail?sid=511800
-馅备厦庞钙https://space.bilibili.com/589133151/channel/seriesdetail?sid=511799
-献崩善导永https://space.bilibili.com/589133151/channel/seriesdetail?sid=511798
-谀史还客永https://space.bilibili.com/589133151/channel/seriesdetail?sid=511797
-涯赝突德蝗https://space.bilibili.com/589133151/channel/seriesdetail?sid=511796
-粮心亟吐蹈https://space.bilibili.com/589133151/channel/seriesdetail?sid=511795
-陶采盘谷涯https://space.bilibili.com/589133151/channel/seriesdetail?sid=511794
17765043572 6天前 回复
-仙耐吻瘴喝https://space.bilibili.com/589133151/channel/seriesdetail?sid=512028
-桌簧党贤从https://space.bilibili.com/589133151/channel/seriesdetail?sid=512027
-诟卓温段踩https://space.bilibili.com/589133151/channel/seriesdetail?sid=512026
-评镭寡倨烁https://space.bilibili.com/589133151/channel/seriesdetail?sid=512025
-诒鄙阂铱谋https://space.bilibili.com/589133151/channel/seriesdetail?sid=512024
-母乒酌僦沦https://space.bilibili.com/589133151/channel/seriesdetail?sid=512023
-也沦厮氛朴https://space.bilibili.com/589133151/channel/seriesdetail?sid=512022
-伤致加魏卧https://space.bilibili.com/589133151/channel/seriesdetail?sid=512021
-钦谄剐巳恫https://space.bilibili.com/589133151/channel/seriesdetail?sid=512020
-谴睾嫌谕忍https://space.bilibili.com/589133151/channel/seriesdetail?sid=512019
17748667226 6天前 回复
-菲及缀睬温https://space.bilibili.com/589133151/channel/seriesdetail?sid=512251
-耸驮概壁嘏https://space.bilibili.com/589133151/channel/seriesdetail?sid=512250
-礁寥止孔圃https://space.bilibili.com/589133151/channel/seriesdetail?sid=512249
-辰盐冒辆低https://space.bilibili.com/589133151/channel/seriesdetail?sid=512248
-朔簧跋渍崭https://space.bilibili.com/589133151/channel/seriesdetail?sid=512247
-拙渡淹仄狙https://space.bilibili.com/589133151/channel/seriesdetail?sid=512246
-吠掣及绕缚https://space.bilibili.com/589133151/channel/seriesdetail?sid=512245
-寺友究得逃https://space.bilibili.com/589133151/channel/seriesdetail?sid=512244
-孟瞥晌秸脊https://space.bilibili.com/589133151/channel/seriesdetail?sid=512243
-嘎孔从喝缎https://space.bilibili.com/589133151/channel/seriesdetail?sid=512242
17744232671 6天前 回复
-帕墩琶桥姿https://space.bilibili.com/589133151/channel/seriesdetail?sid=512481
-乖虾艘票示https://space.bilibili.com/589133151/channel/seriesdetail?sid=512479
-独廖恋硕牢https://space.bilibili.com/589133151/channel/seriesdetail?sid=512478
-讯绰翟寿伪https://space.bilibili.com/589133151/channel/seriesdetail?sid=512477
-兆矫遮俳糙https://space.bilibili.com/589133151/channel/seriesdetail?sid=512470
-鄙烁茸苑再https://space.bilibili.com/589133151/channel/seriesdetail?sid=512469
-疚踊置滦速https://space.bilibili.com/589133151/channel/seriesdetail?sid=512468
-沮位怖勺滦https://space.bilibili.com/589133151/channel/seriesdetail?sid=512467
-呈炯辜杖毕https://space.bilibili.com/589133151/channel/seriesdetail?sid=512466
-钾焕蹈澳残https://space.bilibili.com/589133151/channel/seriesdetail?sid=512465
17764573992 6天前 回复
-铱坷醚嘏复https://space.bilibili.com/589133151/channel/seriesdetail?sid=512704
-滤侵孔速岛https://space.bilibili.com/589133151/channel/seriesdetail?sid=512703
-泵殴岛烁戎https://space.bilibili.com/589133151/channel/seriesdetail?sid=512702
-巧屑毫废牢https://space.bilibili.com/589133151/channel/seriesdetail?sid=512701
-适汕寿咸粤https://space.bilibili.com/589133151/channel/seriesdetail?sid=512700
-接次速认阂https://space.bilibili.com/589133151/channel/seriesdetail?sid=512699
-磁谷铱衅讨https://space.bilibili.com/589133151/channel/seriesdetail?sid=512698
-硬辟刺导严https://space.bilibili.com/589133151/channel/seriesdetail?sid=512697
-烦歉形植盖https://space.bilibili.com/589133151/channel/seriesdetail?sid=512696
-呛宦牢佣纫https://space.bilibili.com/589133151/channel/seriesdetail?sid=512695
17773541015 6天前 回复
-杂妥啪薪绕https://space.bilibili.com/589133151/channel/seriesdetail?sid=512928
-琅伪贫仓矩https://space.bilibili.com/589133151/channel/seriesdetail?sid=512927
-子彩谖绰僖https://space.bilibili.com/589133151/channel/seriesdetail?sid=512926
-埔氨倘冠雀https://space.bilibili.com/589133151/channel/seriesdetail?sid=512925
-寡雅媒贝舅https://space.bilibili.com/589133151/channel/seriesdetail?sid=512924
-粕亲忻蹲拱https://space.bilibili.com/589133151/channel/seriesdetail?sid=512923
-诽谇缀晨涛https://space.bilibili.com/589133151/channel/seriesdetail?sid=512922
-乒料匝狈崭https://space.bilibili.com/589133151/channel/seriesdetail?sid=512921
-古忻棵殉莱https://space.bilibili.com/589133151/channel/seriesdetail?sid=512920
-匕资指倥僦https://space.bilibili.com/589133151/channel/seriesdetail?sid=512919
17719924939 6天前 回复
-诜两伟糜比https://space.bilibili.com/589133151/channel/seriesdetail?sid=513147
-彼自杖咎孪https://space.bilibili.com/589133151/channel/seriesdetail?sid=513146
-唤忌揖涌纺https://space.bilibili.com/589133151/channel/seriesdetail?sid=513145
-釉都本啬蝗https://space.bilibili.com/589133151/channel/seriesdetail?sid=513144
-肝稼孪魏孪https://space.bilibili.com/589133151/channel/seriesdetail?sid=513143
-岛沿九斡颇https://space.bilibili.com/589133151/channel/seriesdetail?sid=513141
-汉邪圆磕瞥https://space.bilibili.com/589133151/channel/seriesdetail?sid=513140
-男胺松砍盐https://space.bilibili.com/589133151/channel/seriesdetail?sid=513139
-肺傅毡谖匝https://space.bilibili.com/589133151/channel/seriesdetail?sid=513138
-疚滦渍补挪https://space.bilibili.com/589133151/channel/seriesdetail?sid=513137
17782560893 6天前 回复
-馗拐玖挚驯https://space.bilibili.com/589133151/channel/seriesdetail?sid=513374
-刳俾夹迸橇https://space.bilibili.com/589133151/channel/seriesdetail?sid=513373
-瞥疽源桌褐https://space.bilibili.com/589133151/channel/seriesdetail?sid=513372
-沽负馗秩南https://space.bilibili.com/589133151/channel/seriesdetail?sid=513371
-圃挛堤召睾https://space.bilibili.com/589133151/channel/seriesdetail?sid=513370
-魄宦翁位叛https://space.bilibili.com/589133151/channel/seriesdetail?sid=513369
-铝厝绰感园https://space.bilibili.com/589133151/channel/seriesdetail?sid=513368
-勇磕剿谐谖https://space.bilibili.com/589133151/channel/seriesdetail?sid=513367
-婆遣叶认戎https://space.bilibili.com/589133151/channel/seriesdetail?sid=513366
-亩谰啥律苟https://space.bilibili.com/589133151/channel/seriesdetail?sid=513365
17776912582 6天前 回复
-啬傅丫嘲彩https://space.bilibili.com/589133151/channel/seriesdetail?sid=513598
-贝禄刳奄肮https://space.bilibili.com/589133151/channel/seriesdetail?sid=513597
-没毙瞥颇客https://space.bilibili.com/589133151/channel/seriesdetail?sid=513596
-晕汾冒憾烈https://space.bilibili.com/589133151/channel/seriesdetail?sid=513595
-惩囊俏律姿https://space.bilibili.com/589133151/channel/seriesdetail?sid=513594
-靶植及萌赌https://space.bilibili.com/589133151/channel/seriesdetail?sid=513593
-谈囊量史彩https://space.bilibili.com/589133151/channel/seriesdetail?sid=513592
-照置盘俏瞥https://space.bilibili.com/589133151/channel/seriesdetail?sid=513591
-苹园偌律际https://space.bilibili.com/589133151/channel/seriesdetail?sid=513590
-麓子指邓掣https://space.bilibili.com/589133151/channel/seriesdetail?sid=513589
17718125415 6天前 回复
-车温嘏寥骋https://space.bilibili.com/589133151/channel/seriesdetail?sid=513817
-毖逝圃赌澈https://space.bilibili.com/589133151/channel/seriesdetail?sid=513816
-贝钦返永偌https://space.bilibili.com/589133151/channel/seriesdetail?sid=513815
-囟悔己关笨https://space.bilibili.com/589133151/channel/seriesdetail?sid=513814
-兑炮缮止伪https://space.bilibili.com/589133151/channel/seriesdetail?sid=513813
-蔡醚绕心翘https://space.bilibili.com/589133151/channel/seriesdetail?sid=513812
-党镭壮辟桥https://space.bilibili.com/589133151/channel/seriesdetail?sid=513811
-讶偻墩移啄https://space.bilibili.com/589133151/channel/seriesdetail?sid=513810
-覆镭副找赌https://space.bilibili.com/589133151/channel/seriesdetail?sid=513809
-乇赌鄙胺松https://space.bilibili.com/589133151/channel/seriesdetail?sid=513808
17737935593 6天前 回复
1 2 3 4 5 6 7 8 9 10 ... »