ocr_image_plugin 0.0.1
ocr_image_plugin: ^0.0.1 copied to clipboard
A new Flutter project.
example/lib/main.dart
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Plugin Image',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
File? _image;
List? _output;
ImagePicker picker = ImagePicker();
// Func này lấy hình ảnh từ thư viện
_pickImageFromGallery() async {
PickedFile? pickedFile =
await picker.getImage(source: ImageSource.gallery, imageQuality: 50);
File image = File(pickedFile!.path);
setState(() {
_image = image;
});
await detect_image(_image!);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Image Picker"),
),
body: SingleChildScrollView(
child: Center(
child: Container(
padding: const EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
if (_image != null)
Image.file(_image!),
RaisedButton(
onPressed: () {
_pickImageFromGallery();
},
child: Text("Select Image"),
),
SizedBox(
height: 16.0,
),
if (_output != null)
Text(
"${_output!}".toString(),
style: Theme.of(context).textTheme.headline3,
)
],
),
),
),
),
);
}
Future<void> detect_image(File image) async {
var output = ["99A-99999", "99A-66666"];
setState(() {
_output = output!;
});
}
}