我的应用程序中有以下小部件:
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: BottomAppBar(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(
icon: Icon(
Icons.photo_library,
size: 30,
),
onPressed: () => _pickImage(ImageSource.gallery),
color: Colors.pink,
),
],
),
),
body: ListView(
children: <Widget>[
if (_imageFile != null) ...[
Container(
padding: EdgeInsets.all(32),
child: Image.file(_imageFile)),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
FlatButton(
color: Colors.blue,
child: Icon(Icons.arrow_forward_ios),
onPressed: () =>
Get.toNamed(
AppRoutes.OCR_DETAILS,
arguments: {'image': _imageFile},
),
),
],
),
]
],
)
);
}
和以下功能来选择图像:
Future _pickImage(ImageSource source) async {
File selected = await ImagePicker.pickImage(source: source);
_imageFile = selected;
_imageLoaded=true;
}
我想导入文件(_imageFile)并在导入后将其显示在当前小部件上。我想使用 GetX 库。非常感谢您的帮助。