dpblu commited on
Commit
5a15d75
ยท
1 Parent(s): 26c225b

Update: modify main.dart in flutter_frontend

Browse files
Files changed (1) hide show
  1. flutter_frontend/lib/main.dart +211 -90
flutter_frontend/lib/main.dart CHANGED
@@ -318,120 +318,241 @@
318
  // }
319
 
320
  // ์„ธ ๋ฒˆ์งธ ๋งˆ์ดํฌ ๋ฒ„ํŠผ ๊ด€๋ จ ๊ตฌํ˜„
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  import 'package:flutter/material.dart';
 
 
322
 
323
  void main() {
324
- runApp(MaterialApp(
325
- home: TranslationScreen(),
326
- debugShowCheckedModeBanner: false,
327
- ));
 
 
 
 
 
 
 
 
 
328
  }
329
 
330
  class TranslationScreen extends StatefulWidget {
 
 
331
  @override
332
- _TranslationScreenState createState() => _TranslationScreenState();
333
  }
334
 
335
  class _TranslationScreenState extends State<TranslationScreen> {
336
  bool isListening = false;
337
- String pronunciation = '';
338
- String standard = '';
 
 
 
 
 
 
 
 
 
339
 
340
- void onMicPressed() {
341
  if (!isListening) {
342
- // ๋“ฃ๊ธฐ ์‹œ์ž‘
343
- setState(() {
344
- isListening = true;
345
- pronunciation = '';
346
- standard = '';
347
- });
348
- } else {
349
- // ๋“ฃ๊ธฐ ์ข…๋ฃŒ โ†’ ๊ฒฐ๊ณผ ํ‘œ์‹œ
350
- setState(() {
351
- isListening = false;
352
- pronunciation = '์ง€๊ธˆ ๋ช‡ ๋…„ ์•ˆ ๋˜์–ด์ˆ˜๋‹ค๋งˆ๋Š”';
353
- standard = '์ง€๊ธˆ ๋ช‡ ๋…„ ์•ˆ ๋˜์—ˆ์ž–์•„์š”';
354
- });
 
 
 
 
 
 
 
 
 
355
  }
356
  }
357
 
358
  @override
359
  Widget build(BuildContext context) {
360
  return Scaffold(
361
- appBar: AppBar(
362
- title: Text('Jeju Potato'),
363
- backgroundColor: Colors.white,
364
- foregroundColor: Colors.black,
365
- elevation: 0.5,
366
- ),
367
- body: Column(
368
- mainAxisAlignment: MainAxisAlignment.center,
369
- children: [
370
- // ๋งˆ์ดํฌ ๋ฒ„ํŠผ
371
- IconButton(
372
- iconSize: 64,
373
- icon: Icon(
374
- isListening ? Icons.mic : Icons.mic_none,
375
- color: isListening ? Colors.red : Colors.black,
376
  ),
377
- onPressed: onMicPressed,
378
- ),
379
-
380
- // ๋“ฃ๋Š” ์ค‘โ€ฆ ํ‘œ์‹œ
381
- if (isListening)
382
- Padding(
383
- padding: const EdgeInsets.only(top: 8.0),
384
- child: Text(
385
- '๋“ฃ๋Š” ์ค‘โ€ฆ',
386
- style: TextStyle(fontSize: 16, fontStyle: FontStyle.italic),
 
 
387
  ),
 
388
  ),
389
-
390
- SizedBox(height: 24),
391
-
392
- // Pronunciation ์นด๋“œ
393
- _buildTextCard('Pronunciation', pronunciation),
394
-
395
- SizedBox(height: 16),
396
-
397
- // Standard ์นด๋“œ
398
- _buildTextCard('Standard', standard),
399
- ],
400
- ),
401
- bottomNavigationBar: BottomNavigationBar(
402
- items: const [
403
- BottomNavigationBarItem(icon: Icon(Icons.home), label: ''),
404
- BottomNavigationBarItem(icon: Icon(Icons.search), label: ''),
405
- BottomNavigationBarItem(icon: Icon(Icons.reply), label: ''),
406
- BottomNavigationBarItem(icon: Icon(Icons.bookmark_border), label: ''),
407
- ],
408
- selectedItemColor: Colors.black,
409
- unselectedItemColor: Colors.grey,
410
- type: BottomNavigationBarType.fixed,
411
- ),
412
- );
413
- }
414
-
415
- Widget _buildTextCard(String title, String content) {
416
- return Padding(
417
- padding: const EdgeInsets.symmetric(horizontal: 20),
418
- child: Card(
419
- elevation: 1,
420
- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
421
- child: Container(
422
- width: double.infinity,
423
- padding: EdgeInsets.all(16),
424
- child: Column(
425
- crossAxisAlignment: CrossAxisAlignment.start,
426
- children: [
427
- Text(title, style: TextStyle(fontWeight: FontWeight.bold)),
428
- SizedBox(height: 8),
429
- Text(content.isEmpty ? ' ' : content),
430
- ],
431
- ),
432
  ),
433
  ),
434
  );
435
  }
436
  }
437
-
 
318
  // }
319
 
320
  // ์„ธ ๋ฒˆ์งธ ๋งˆ์ดํฌ ๋ฒ„ํŠผ ๊ด€๋ จ ๊ตฌํ˜„
321
+ // import 'package:flutter/material.dart';
322
+
323
+ // void main() {
324
+ // runApp(MaterialApp(
325
+ // home: TranslationScreen(),
326
+ // debugShowCheckedModeBanner: false,
327
+ // ));
328
+ // }
329
+
330
+ // class TranslationScreen extends StatefulWidget {
331
+ // @override
332
+ // _TranslationScreenState createState() => _TranslationScreenState();
333
+ // }
334
+
335
+ // class _TranslationScreenState extends State<TranslationScreen> {
336
+ // bool isListening = false;
337
+ // String pronunciation = '';
338
+ // String standard = '';
339
+
340
+ // void onMicPressed() {
341
+ // if (!isListening) {
342
+ // // ๋“ฃ๊ธฐ ์‹œ์ž‘
343
+ // setState(() {
344
+ // isListening = true;
345
+ // pronunciation = '';
346
+ // standard = '';
347
+ // });
348
+ // } else {
349
+ // // ๋“ฃ๊ธฐ ์ข…๋ฃŒ โ†’ ๊ฒฐ๊ณผ ํ‘œ์‹œ
350
+ // setState(() {
351
+ // isListening = false;
352
+ // pronunciation = '์ง€๊ธˆ ๋ช‡ ๋…„ ์•ˆ ๋˜์–ด์ˆ˜๋‹ค๋งˆ๋Š”';
353
+ // standard = '์ง€๊ธˆ ๋ช‡ ๋…„ ์•ˆ ๋˜์—ˆ์ž–์•„์š”';
354
+ // });
355
+ // }
356
+ // }
357
+
358
+ // @override
359
+ // Widget build(BuildContext context) {
360
+ // return Scaffold(
361
+ // appBar: AppBar(
362
+ // title: Text('Jeju Potato'),
363
+ // backgroundColor: Colors.white,
364
+ // foregroundColor: Colors.black,
365
+ // elevation: 0.5,
366
+ // ),
367
+ // body: Column(
368
+ // mainAxisAlignment: MainAxisAlignment.center,
369
+ // children: [
370
+ // // ๋งˆ์ดํฌ ๋ฒ„ํŠผ
371
+ // IconButton(
372
+ // iconSize: 64,
373
+ // icon: Icon(
374
+ // isListening ? Icons.mic : Icons.mic_none,
375
+ // color: isListening ? Colors.red : Colors.black,
376
+ // ),
377
+ // onPressed: onMicPressed,
378
+ // ),
379
+
380
+ // // ๋“ฃ๋Š” ์ค‘โ€ฆ ํ‘œ์‹œ
381
+ // if (isListening)
382
+ // Padding(
383
+ // padding: const EdgeInsets.only(top: 8.0),
384
+ // child: Text(
385
+ // '๋“ฃ๋Š” ์ค‘โ€ฆ',
386
+ // style: TextStyle(fontSize: 16, fontStyle: FontStyle.italic),
387
+ // ),
388
+ // ),
389
+
390
+ // SizedBox(height: 24),
391
+
392
+ // // Pronunciation ์นด๋“œ
393
+ // _buildTextCard('Pronunciation', pronunciation),
394
+
395
+ // SizedBox(height: 16),
396
+
397
+ // // Standard ์นด๋“œ
398
+ // _buildTextCard('Standard', standard),
399
+ // ],
400
+ // ),
401
+ // bottomNavigationBar: BottomNavigationBar(
402
+ // items: const [
403
+ // BottomNavigationBarItem(icon: Icon(Icons.home), label: ''),
404
+ // BottomNavigationBarItem(icon: Icon(Icons.search), label: ''),
405
+ // BottomNavigationBarItem(icon: Icon(Icons.reply), label: ''),
406
+ // BottomNavigationBarItem(icon: Icon(Icons.bookmark_border), label: ''),
407
+ // ],
408
+ // selectedItemColor: Colors.black,
409
+ // unselectedItemColor: Colors.grey,
410
+ // type: BottomNavigationBarType.fixed,
411
+ // ),
412
+ // );
413
+ // }
414
+
415
+ // Widget _buildTextCard(String title, String content) {
416
+ // return Padding(
417
+ // padding: const EdgeInsets.symmetric(horizontal: 20),
418
+ // child: Card(
419
+ // elevation: 1,
420
+ // shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
421
+ // child: Container(
422
+ // width: double.infinity,
423
+ // padding: EdgeInsets.all(16),
424
+ // child: Column(
425
+ // crossAxisAlignment: CrossAxisAlignment.start,
426
+ // children: [
427
+ // Text(title, style: TextStyle(fontWeight: FontWeight.bold)),
428
+ // SizedBox(height: 8),
429
+ // Text(content.isEmpty ? ' ' : content),
430
+ // ],
431
+ // ),
432
+ // ),
433
+ // ),
434
+ // );
435
+ // }
436
+ // }
437
+
438
+
439
+ // ๋ฐฑ์—”๋“œ์™€ ์—ฐ๊ฒฐํ•œ ๋ฒ„์ „
440
  import 'package:flutter/material.dart';
441
+ import 'package:http/http.dart' as http;
442
+ import 'dart:convert';
443
 
444
  void main() {
445
+ runApp(const MyApp());
446
+ }
447
+
448
+ class MyApp extends StatelessWidget {
449
+ const MyApp({super.key});
450
+
451
+ @override
452
+ Widget build(BuildContext context) {
453
+ return const MaterialApp(
454
+ debugShowCheckedModeBanner: false,
455
+ home: TranslationScreen(),
456
+ );
457
+ }
458
  }
459
 
460
  class TranslationScreen extends StatefulWidget {
461
+ const TranslationScreen({super.key});
462
+
463
  @override
464
+ State<TranslationScreen> createState() => _TranslationScreenState();
465
  }
466
 
467
  class _TranslationScreenState extends State<TranslationScreen> {
468
  bool isListening = false;
469
+ String pronunciationText = '';
470
+ String standardText = '';
471
+
472
+ Future<void> onMicPressed() async {
473
+ setState(() {
474
+ isListening = !isListening;
475
+ if (isListening) {
476
+ pronunciationText = '';
477
+ standardText = '';
478
+ }
479
+ });
480
 
 
481
  if (!isListening) {
482
+ // ๋งˆ์ดํฌ ์ž…๋ ฅ ์ข…๋ฃŒ ์‹œ ๋ฐฑ์—”๋“œ ํ˜ธ์ถœ
483
+ final url = Uri.parse('http://127.0.0.1:8000/test_random'); // ์‹ค์ œ IP๋‚˜ ๋„๋ฉ”์ธ์œผ๋กœ ๋ณ€๊ฒฝ ๊ฐ€๋Šฅ
484
+ try {
485
+ final response = await http.get(url);
486
+ if (response.statusCode == 200) {
487
+ final data = json.decode(response.body);
488
+ setState(() {
489
+ pronunciationText = data['whisper_result'] ?? '';
490
+ standardText = data['second_kobart_result'] ?? '';
491
+ });
492
+ } else {
493
+ setState(() {
494
+ pronunciationText = '์„œ๋ฒ„ ์—๋Ÿฌ ๋ฐœ์ƒ';
495
+ standardText = '';
496
+ });
497
+ }
498
+ } catch (e) {
499
+ setState(() {
500
+ pronunciationText = '๋„คํŠธ์›Œํฌ ์˜ค๋ฅ˜: $e';
501
+ standardText = '';
502
+ });
503
+ }
504
  }
505
  }
506
 
507
  @override
508
  Widget build(BuildContext context) {
509
  return Scaffold(
510
+ appBar: AppBar(title: const Text('Jeju Potato')),
511
+ body: Padding(
512
+ padding: const EdgeInsets.all(20),
513
+ child: Column(
514
+ mainAxisAlignment: MainAxisAlignment.center,
515
+ children: [
516
+ ElevatedButton.icon(
517
+ onPressed: onMicPressed,
518
+ icon: const Icon(Icons.mic),
519
+ label: Text(isListening ? '๋“ฃ๋Š” ์ค‘...' : '๋งํ•˜๊ธฐ'),
520
+ style: ElevatedButton.styleFrom(
521
+ padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
522
+ ),
 
 
523
  ),
524
+ const SizedBox(height: 30),
525
+ Align(
526
+ alignment: Alignment.centerLeft,
527
+ child: Text('Pronunciation', style: TextStyle(fontWeight: FontWeight.bold)),
528
+ ),
529
+ Container(
530
+ width: double.infinity,
531
+ padding: const EdgeInsets.all(16),
532
+ margin: const EdgeInsets.only(bottom: 20, top: 8),
533
+ decoration: BoxDecoration(
534
+ border: Border.all(color: Colors.grey),
535
+ borderRadius: BorderRadius.circular(12),
536
  ),
537
+ child: Text(pronunciationText),
538
  ),
539
+ Align(
540
+ alignment: Alignment.centerLeft,
541
+ child: Text('Standard', style: TextStyle(fontWeight: FontWeight.bold)),
542
+ ),
543
+ Container(
544
+ width: double.infinity,
545
+ padding: const EdgeInsets.all(16),
546
+ margin: const EdgeInsets.only(top: 8),
547
+ decoration: BoxDecoration(
548
+ border: Border.all(color: Colors.grey),
549
+ borderRadius: BorderRadius.circular(12),
550
+ ),
551
+ child: Text(standardText),
552
+ ),
553
+ ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
554
  ),
555
  ),
556
  );
557
  }
558
  }