flutter-package / flutter_scan

scanner qrcode in widget tree & decoder qrcode from image
MIT License
79 stars 66 forks source link

onCapture: (data) { } #27

Closed JP3871 closed 2 years ago

JP3871 commented 2 years ago

Environment

Technology Version
Flutter version 2.2.3 stable
Plugin version scan: ^1.5.0
Android version 11
iOS version
Xcode version

Device information: Xiaomi Mi Note 10 Lite

Description

Hi, the scan works fine. I added in the source : onCapture: (data) { setState(() async { _codeCB = data; // get barecode

await getDescArt(_codeCB); // Fetch MysqL data (description and qty in stock) for barecode if (artDesc == '£NULL£_') showDialog( context: context, builder: (BuildContext context) { return AlertDialog( //title: Text('ok'), content: Text('Barcode invalid !), actions: [ ElevatedButton( onPressed: () { Navigator.of(context).pop(); }, child: Text("OK")) ], ); }); else { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( //title: Text('ok'), content: Text(_artDesc + "-" + widget.userID), actions: [ ElevatedButton( onPressed: () { Navigator.of(context).pop(); }, child: Text("OK")) ], ); }); Navigator.of(context).push(MaterialPageRoute( builder: (BuildContext context) => new SortieArticle( nomArticle: _artDesc, idArticle: _idArt, qteStock: _qteStock, qteOut: _qteOut, userScan: widget.userID, ))); } }

It seems that after this line : _codeCB = data; // get barecode This call await getDescArt(_codeCB); never reachs... If I comment this line, I can show the dialog

Do you know why ?

Thank for your answer

chavesgu commented 2 years ago

setState is not support async function


该邮件从移动设备发送

--------------原始邮件-------------- 发件人:"JP3871 @.>; 发送时间:2021年11月21日(星期天) 晚上11:25 收件人:"flutter-package/flutter_scan" @.>; 抄送:"Subscribed @.***>; 主题:[flutter-package/flutter_scan] onCapture: (data) { } (Issue #27)

I have read the Get Started - Installation section

I have read and done the Get Started - Setup Android section

I have read and done the Get Started - Setup iOS section

I have already searched for the same problem

Environment Technology Version Flutter version 2.2.3 stable Plugin version scan: ^1.5.0 Android version 11 iOS version
Xcode version

Device information: Xiaomi Mi Note 10 Lite

Description

Hi, the scan works fine. I added in the source : onCapture: (data) { setState(() async { _codeCB = data; // get barecode

await getDescArt(_codeCB); // Fetch MysqL data (description and qty in stock) for barecode if (_artDesc == '£NULL£') showDialog( context: context, builder: (BuildContext context) { return AlertDialog( //title: Text('ok'), content: Text('Barcode invalid !), actions: [ ElevatedButton( onPressed: () { Navigator.of(context).pop(); }, child: Text("OK")) ], ); }); else { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( //title: Text('ok'), content: Text(_artDesc + "-" + widget.userID), actions: [ ElevatedButton( onPressed: () { Navigator.of(context).pop(); }, child: Text("OK")) ], ); }); Navigator.of(context).push(MaterialPageRoute( builder: (BuildContext context) => new SortieArticle( nomArticle: _artDesc, idArticle: _idArt, qteStock: _qteStock, qteOut: _qteOut, userScan: widget.userID, ))); } }

It seems that after this line : _codeCB = data; // get barecode This call await getDescArt(_codeCB); never reachs... If I comment this line, I can show the dialog

Do you know why ?

Thank for your answer

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

JP3871 commented 2 years ago

Hi,

Even I call MaterialPageRoute, async doesn't want to launch correctly... Do you know how to call async (fetchData from MySQL) before build ? Thanks

                  onCapture: (data) {
                    Navigator.of(context).push(MaterialPageRoute(
                        builder: (BuildContext context) =>
                            new SortieArticle(
                              cbArticle: data,
                              userScan: widget.userID,
                            )));
                  }))

class SortieArticle extends StatefulWidget { // parametre en entree final String cbArticle; final String userScan;

const SortieArticle( {Key? key, required this.cbArticle, required this.userScan}) : super(key: key);

@override _MySortieArticleState createState() => _MySortieArticleState(); }

class _MySortieArticleState extends State {

Widget build(BuildContext context) { var test = FutureBuilder( future: getData(), builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.waiting) return CircularProgressIndicator(); else if (snapshot.connectionState == ConnectionState.done) { if (snapshot.hasError) return Text('Ko'); else if (snapshot.hasData) { return Column(children: [ Text('\n\n'), Container( height: 65.0, width: double.infinity, color: Colors.blue, alignment: Alignment.bottomRight, child: Center( child: Text(descArticle + "--" + widget.cbArticle, softWrap: true, textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontSize: 25)), )), Text('\n'), Container( height: 50.0, width: double.infinity, ...

return MaterialApp(
    debugShowCheckedModeBanner: false,
    home: Scaffold(
        appBar: AppBar(
          title: const Text('Becker Racine Sortie Stock'),
        ),
        body: test));

}