Reputation: 71
I'm supposed to call a Barcode scanner in Expansion Tile as a child. I could call the scanner using a function.The Scanner is being opened in a full screen. As I mentioned earlier my requirement is to call it as a child of ExpansionTile in a container with certain dimensions.
I used flutter_barcode_scanner: ^0.0.9
package for the scanner.
here is the code I tried.
class ExpansionTileSample extends StatefulWidget {
@override
ExpansionTileSampleState createState() => new ExpansionTileSampleState();
}
class ExpansionTileSampleState extends State<ExpansionTileSample> {
final GlobalKey<AppExpansionTileState> expansionTile = new GlobalKey();
String barcode,value="";
bool expand = false;
onExpansionChanged(bool val) {
setState(() {
expand = !expand;
if (expand) {
barcodeScan();
} else {
print("Closed");
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: const Text('ExpansionTile'),
),
body: new AppExpansionTile(
onExpansionChanged: onExpansionChanged,
key: expansionTile,
title: new Text(value),
backgroundColor: Theme.of(context).accentColor.withOpacity(0.025),
child: expand ? Text("done") : Text("not done"),
),
);
}
Future barcodeScan() async{
barcode=await FlutterBarcodeScanner.scanBarcode("#004297", "cancel", false);
setState(() {
value=barcode;
});
}
}
How do I call the function(since it is not a widget, I cannot call it as a child) in place of child: expand ? Text("done") : Text("not done"),
in my code?
Upvotes: 2
Views: 2161
Reputation: 2436
Instead of flutter_barcode_scanner
plugin, you can use fast_qr_reader_view
which will provide you QRReaderPreview
widget.
By that you will be able to achieve your requirement.
Upvotes: 2