【发布时间】:2021-09-28 16:34:46
【问题描述】:
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
backgroundColor: Colors.transparent,
// appBar: AppBar(
// title: Text('Future Demo Page'),
// ),
body: FutureBuilder(
builder: (ctx, snapshot) {
// Checking if future is resolved or not
if (snapshot.connectionState == ConnectionState.done) {
// If we got an error
if (snapshot.hasError) {
return Center(
child: Text(
'${snapshot.error} occured',
style: TextStyle(fontSize: 18),
),
);
// if we got our data
} else if (snapshot.hasData) {
// Extracting data from snapshot object
final data = snapshot.data as String;
getGoodsData(data);
// return getGoodsData(data);
}
}
// Displaying LoadingSpinner to indicate waiting state
return Center(
child: CircularProgressIndicator(),
);
},
// Future that needs to be resolved
// inorder to display something on the Canvas
future: startBarcodeScanStream(),
),
),
);
}
Future<void> startBarcodeScanStream() async {
FlutterBarcodeScanner.getBarcodeStreamReceiver(
'#ff6666', 'Cancel', true, ScanMode.BARCODE)
.listen((barcode) {
// if (!mounted) return;
this.barcodeScanner = barcode;
print(barcode);
// Don't show form if barcode sacnner is cancelled
if (barcode == "-1") {
Navigator.pop(context);
}
});
return barcodeScanner;
}
我正在我的颤振应用程序中实现条形码扫描仪。扫描完成后,我想在扫描中心显示 progressIndicator,我必须调用 api。上面的代码没有显示任何进度指示器。
注意:我想在扫描后在扫描仪的中心显示 progressIndicator 并且我必须调用 api 一个响应成功我必须隐藏那个进度指示器。
【问题讨论】: