@@ -17,11 +17,25 @@ class _CameraScreenState extends State<CameraScreen> {
1717 String _recognizedText = 'Tekan capture untuk scan teks' ;
1818 bool _isProcessing = false ;
1919
20+ TextRecognitionScript _currentScript = TextRecognitionScript .latin;
21+
2022 @override
2123 void initState () {
2224 super .initState ();
2325 _initializeCamera ();
24- _textRecognizer = TextRecognizer (script: TextRecognitionScript .latin);
26+ // _textRecognizer = TextRecognizer(script: TextRecognitionScript.latin);
27+ _textRecognizer = TextRecognizer (script: _currentScript);
28+ }
29+
30+ // Method untuk ganti bahasa
31+ void _changeLanguage (TextRecognitionScript newScript) {
32+ _textRecognizer.close ();
33+
34+ // buat recognizer baru dengan bahasa yang ingin dipilih
35+ setState (() {
36+ _currentScript = newScript;
37+ _textRecognizer = TextRecognizer (script: _currentScript);
38+ });
2539 }
2640
2741 void _initializeCamera () async {
@@ -67,6 +81,58 @@ class _CameraScreenState extends State<CameraScreen> {
6781 }
6882 }
6983
84+ void _showLanguageSelection () { // Dialog Language Selection
85+ showDialog (
86+ context: context,
87+ builder: (BuildContext context) {
88+ return AlertDialog (
89+ title: Text ('Pilih Bahasa' ),
90+ content: SingleChildScrollView (
91+ child: Column (
92+ children: [
93+ ListTile (
94+ title: Text ('English, Indonesia, dll' ),
95+ onTap: () {
96+ Navigator .pop (context);
97+ _changeLanguage (TextRecognitionScript .latin);
98+ },
99+ ),
100+ ListTile (
101+ title: Text ('Chinese' ),
102+ onTap: () {
103+ Navigator .pop (context);
104+ _changeLanguage (TextRecognitionScript .chinese);
105+ },
106+ ),
107+ ListTile (
108+ title: Text ('Devanagari' ),
109+ onTap: () {
110+ Navigator .pop (context);
111+ _changeLanguage (TextRecognitionScript .devanagiri);
112+ },
113+ ),
114+ ListTile (
115+ title: Text ('Japanese' ),
116+ onTap: () {
117+ Navigator .pop (context);
118+ _changeLanguage (TextRecognitionScript .japanese);
119+ },
120+ ),
121+ ListTile (
122+ title: Text ('Korean' ),
123+ onTap: () {
124+ Navigator .pop (context);
125+ _changeLanguage (TextRecognitionScript .korean);
126+ },
127+ ),
128+ ],
129+ ),
130+ ),
131+ );
132+ }
133+ );
134+ }
135+
70136 // memilih sumber gambar
71137 void _showImageSourceSelection () {
72138 showModalBottomSheet (
@@ -203,6 +269,43 @@ class _CameraScreenState extends State<CameraScreen> {
203269 }
204270
205271 return Scaffold (
272+ appBar: AppBar (
273+ actions: [
274+ DropdownButton <TextRecognitionScript >( //* Dropdown button untuk pilihan bahasa
275+ value: _currentScript,
276+ icon: Icon (Icons .language, color: Colors .black),
277+ dropdownColor: Colors .blue,
278+ onChanged: (TextRecognitionScript ? newScript) {
279+ if (newScript != null ) {
280+ _changeLanguage (newScript);
281+ }
282+ },
283+ items: [
284+ DropdownMenuItem (
285+ value: TextRecognitionScript .latin,
286+ child: Text ('Latin' , style: TextStyle (color: Colors .black)),
287+ ),
288+ DropdownMenuItem (
289+ value: TextRecognitionScript .chinese,
290+ child: Text ('Chinese' , style: TextStyle (color: Colors .black)),
291+ ),
292+ DropdownMenuItem (
293+ value: TextRecognitionScript .devanagiri,
294+ child: Text ('Devanagiri' , style: TextStyle (color: Colors .black)),
295+ ),
296+ DropdownMenuItem (
297+ value: TextRecognitionScript .japanese,
298+ child: Text ('Japanese' , style: TextStyle (color: Colors .black)),
299+ ),
300+ DropdownMenuItem (
301+ value: TextRecognitionScript .korean,
302+ child: Text ('Korean' , style: TextStyle (color: Colors .black)),
303+ ),
304+ ],
305+ ),
306+ SizedBox (width: 20 ),
307+ ],
308+ ),
206309 body: Column (
207310 children: [
208311 Expanded (
@@ -242,6 +345,12 @@ class _CameraScreenState extends State<CameraScreen> {
242345 backgroundColor: Colors .green,
243346 child: Icon (Icons .photo_library)
244347 ),
348+ SizedBox (width: 20 ),
349+ FloatingActionButton (
350+ onPressed: _showLanguageSelection,
351+ backgroundColor: Colors .orange,
352+ child: Icon (Icons .language)
353+ ),
245354 ],
246355 ),
247356 ),
0 commit comments