如何将从我的条形码扫描器接收到的扫描结果数据解析为颤动的新屏幕或页面

How can I parse the scanned result data received from my barcode scanner to a new screen or page in flutter

这是因为我正在尝试实现一个条形码 reader 来扫描员工身份证。所以,我想要实现的是,当分配给扫描卡的代理执行扫描时,它应该在另一个页面上显示扫描结果,而不是同一个屏幕或小部件。

简单来说,就像你有待办事项列表,当你点击一个待办事项时,它会找到待办事项 ID 并将你带到待办事项详细信息页面。这意味着 link 到员工详细信息页面将被编码为条形码,因此当您扫描它时,它将带您到员工详细信息页面。但我不知道该怎么做。

这就是我在下面所做的。这执行扫描非常好,但显示结果是问题。

import 'dart:async';
import 'package:erg_app/ScanPage.dart';
import 'package:erg_app/eops.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:barcode_scan/barcode_scan.dart';
import 'package:erg_app/Animations/FadeAnimation.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(
    MaterialApp(
      debugShowCheckedModeBanner: false,
      home: StartScanPage(),
    )
  );
}

class StartScanPage extends StatefulWidget {
  @override
  StartScanPageState createState() {
      return StartScanPageState();
  }
}

  class StartScanPageState extends State<StartScanPage>  {

  String result = "Bio Data:";

  Future _scanQR() async {
    try {
      String qrResult = await BarcodeScanner.scan();

      setState(() {
        result = qrResult; 
      });
    } on PlatformException catch (ex) {
      if (ex.code == BarcodeScanner.CameraAccessDenied) {
        setState(() {
          result = "Camera permission was denied";
        });
      } else {
        setState(() {
          result = "Unknown Error $ex";
        });
      }
    } on FormatException {
      setState(() {
        result = "You pressed the back button before scanning anything";
      });
    } catch (ex) {
      setState(() {
        result = "Unknown Error $ex";
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Container(
          width: double.infinity,
          height: MediaQuery.of(context).size.height,
          padding: EdgeInsets.symmetric(horizontal: 30, vertical: 50),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              Column(
                children: <Widget>[
                  FadeAnimation(1, Text("Verify Farmer", 
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: 30
                  ),)),
                  SizedBox(height: 20,),
                  FadeAnimation(1.2, Text("Automatic identity verification which enables you to verify each farmer applicant", 
                  textAlign: TextAlign.center,
                  style: TextStyle(
                    color: Colors.grey[700],
                    fontSize: 15
                  ),)),
                ],
              ),
              FadeAnimation(1.4, Container(
                height: MediaQuery.of(context).size.height / 3,
                decoration: BoxDecoration(
                  image: DecorationImage(
                    image: AssetImage('assets/images/illustration1.png')
                  )
                ),
              )),
              Column(
                children: <Widget>[
                  FadeAnimation(1.5, MaterialButton(
                    color: Colors.green,
                    minWidth: double.infinity,
                    height: 60,
                    onPressed: _scanQR,
                    // () {
                    //   Navigator.push(context, MaterialPageRoute(builder: (context) => ScanPage()));
                    // },
                    shape: RoundedRectangleBorder(
                      side: BorderSide(
                        color: Colors.green
                      ),
                      borderRadius: BorderRadius.circular(50)
                    ),
                    child: Text("Start Scan", style: TextStyle(
                      color: Colors.white,
                      fontWeight: FontWeight.w600, 
                      fontSize: 18
                    ),),
                  )),
                  SizedBox(height: 20,),
                  FadeAnimation(1.6, Container(
                    // padding: EdgeInsets.only(top: 3, left: 3),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(50),
                      border: Border(
                        bottom: BorderSide(color: Colors.green),
                        top: BorderSide(color: Colors.green),
                        left: BorderSide(color: Colors.green),
                        right: BorderSide(color: Colors.green),
                      )
                    ),
                    child: MaterialButton(
                      minWidth: double.infinity,
                      height: 60,
                      onPressed: () {
                        Navigator.push(context, MaterialPageRoute(builder: (context) => EopPage()));
                      },
                      color: Colors.white,
                      elevation: 0,
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(50)
                      ),
                      child: Text("Cancel", style: TextStyle(
                        // color: Colors.white,
                        fontWeight: FontWeight.w600, 
                        fontSize: 18
                       ), ),
                    ),
                  ))
                ],
              )
            ],
          ),
        ),
      ),
    );
  }
}

我想在这里显示结果:

import 'package:flutter/material.dart';
import 'package:erg_app/CaptureInputsPage.dart';

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

class ProfilePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
       debugShowCheckedModeBanner: false,
      home: Scaffold(
         appBar: AppBar(
          title: new Center(child: Text('Farmers Data', textAlign: TextAlign.left)),
          iconTheme: IconThemeData(color: Colors.white),
          backgroundColor: Colors.green, 
          leading: IconButton(
          icon: Icon(Icons.assignment_ind),
          onPressed: () {},
        ),

        ),
        body: Container(
          child: ListView(
              children: <Widget>[
                Container(margin: EdgeInsets.only(top: 20),),
                CircleAvatar(
                  radius: 80,
                  backgroundColor: Colors.grey,
                ),
                Text(
                  'Yusuf Danladi',
                  style: TextStyle(
                    fontFamily: 'SourceSansPro',
                    fontSize: 25,
                  ),
                  textAlign: TextAlign.center,
                ),
                Text(
                  'Welcome',
                  style: TextStyle(
                    fontSize: 20,
                    fontFamily: 'SourceSansPro',
                    color: Colors.green[400],
                    letterSpacing: 2.5,
                  ),
                 textAlign: TextAlign.center,
                ),
                Container(margin: EdgeInsets.only(top: 20),),
                SizedBox(
                  height: 20.0,
                  width: 200,
                  child: Divider(
                    color: Colors.teal[100],
                  ),
                ),
                Text(
                  'Farmer Details',
                  textAlign: TextAlign.center,
                ),
                Card(
                      color: Colors.white,
                      margin:
                          EdgeInsets.symmetric(vertical: 10.0, horizontal: 25.0),
                      child: ListTile(
                        leading: Text(
                            'Phone:',
                            style: TextStyle(
                              fontSize: 20,
                              fontFamily: 'SourceSansPro',
                              color: Colors.green[700],
                              letterSpacing: 2.5,
                          ),
                        ),
                        title: Text(
                          '+234 801 000 4504',
                          style:
                              TextStyle(fontFamily: 'BalooBhai', fontSize: 20.0),
                        ), 
                      ), 
                    ),

                    Card(
                      color: Colors.white,
                      margin:
                          EdgeInsets.symmetric(vertical: 10.0, horizontal: 25.0),
                      child: ListTile(
                        leading: Text(
                            'BVN:',
                            style: TextStyle(
                              fontSize: 20,
                              fontFamily: 'SourceSansPro',
                              color: Colors.green[700],
                              letterSpacing: 2.5,
                          ),
                        ),
                        title: Text(
                          '22108691911',
                          style:
                              TextStyle(fontFamily: 'BalooBhai', fontSize: 20.0),
                        ), 
                      ), 
                    ),

                    Card(
                      color: Colors.white,
                      margin:
                          EdgeInsets.symmetric(vertical: 10.0, horizontal: 25.0),
                      child: ListTile(
                        leading: Text(
                            'Appicant ID:',
                            style: TextStyle(
                              fontSize: 20,
                              fontFamily: 'SourceSansPro',
                              color: Colors.green[700],
                              letterSpacing: 2.5,
                          ),
                        ),
                        title: Text(
                          'ERG-108691911',
                          style:
                              TextStyle(fontFamily: 'BalooBhai', fontSize: 20.0),
                        ), 
                      ), 
                    ),

                    Card(
                      color: Colors.white,
                      margin:
                          EdgeInsets.symmetric(vertical: 10.0, horizontal: 25.0),
                      child: ListTile(
                        leading: Text(
                            'State/LGA:',
                            style: TextStyle(
                              fontSize: 20,
                              fontFamily: 'SourceSansPro',
                              color: Colors.green[700],
                              letterSpacing: 2.5,
                          ),
                        ),
                        title: Text(
                          'Taraba/Ussa',
                          style:
                              TextStyle(fontFamily: 'BalooBhai', fontSize: 20.0),
                        ), 
                      ), 
                    ),

                    Card(
                      color: Colors.white,
                      margin:
                          EdgeInsets.symmetric(vertical: 10.0, horizontal: 25.0),
                      child: ListTile(
                        leading: Text(
                            'Farm Size:',
                            style: TextStyle(
                              fontSize: 20,
                              fontFamily: 'SourceSansPro',
                              color: Colors.green[700],
                              letterSpacing: 2.5,
                          ),
                        ),
                        title: Text(
                          '5000 meter sq',
                          style:
                              TextStyle(fontFamily: 'BalooBhai', fontSize: 20.0),
                        ), 
                      ), 
                    ),

                    Card(
                      color: Colors.white,
                      margin:
                          EdgeInsets.symmetric(vertical: 10.0, horizontal: 25.0),
                      child: ListTile(
                        leading: Text(
                            'Geo Coord.:',
                            style: TextStyle(
                              fontSize: 20,
                              fontFamily: 'SourceSansPro',
                              color: Colors.green[700],
                              letterSpacing: 2.5,
                          ),
                        ),
                        title: Text(
                          '012350007, 038245543',
                          style:
                              TextStyle(fontFamily: 'BalooBhai', fontSize: 20.0),
                        ), 
                      ), 
                    ),

                    Container(
                      margin: EdgeInsets.only(top: 20, bottom: 30),
                      child: Center(
                        child: RaisedButton(
                          padding: EdgeInsets.fromLTRB(80, 10, 80, 10),
                          color: Colors.green,
                          child: Text("Complete", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 14), ),
                          onPressed: () {
                            Navigator.of(context).push(MaterialPageRoute(builder: (context) => CaptureInputsPage()));
                          },
                          shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(50),
                        ),
                        ),
                      ),
                  ),
              ],
          ),
        ), 
      ),
    );
  }
}

通过二维码获取结果后,您可以简单地使用MaterialPageRoute。

  Future _scanQR() async {
    try {
      String qrResult = await BarcodeScanner.scan();

      Navigator.of(context).push(
        MaterialPageRoute(
          builder: (context) => ProfilePage(qrResult),
        ),
      );
    } on PlatformException catch (ex) {
      ....
    }
  }

创建 ProfilePage 为

class ProfilePage extends StatelessWidget {
  final String result;

  ProfilePage(this.result);

  ....
}