From f9b8434ddf49e25bf1ad88593dacaf21765ced63 Mon Sep 17 00:00:00 2001 From: paoloGuagnano Date: Fri, 29 Mar 2024 17:17:40 +0100 Subject: [PATCH] modify layout and add function to print error and text translate --- motula_translate_app/lib/constants.dart | 2 +- .../entryPoint/components/animated_bar.dart | 2 +- .../entryPoint/components/side_bar.dart | 2 +- .../entryPoint/components/side_menu.dart | 2 +- .../lib/screens/entryPoint/entry_point.dart | 5 +- .../screens/home/components/words_screen.dart | 12 +-- .../lib/screens/home/home_screen.dart | 75 +++++++++++++++---- 7 files changed, 71 insertions(+), 29 deletions(-) diff --git a/motula_translate_app/lib/constants.dart b/motula_translate_app/lib/constants.dart index 2a8cb11..a3582f2 100644 --- a/motula_translate_app/lib/constants.dart +++ b/motula_translate_app/lib/constants.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -const Color backgroundColor2 = Color(0xFF17203A); +const Color backgroundColor2 = Color(0xFFDF930B); const Color backgroundColorLight = Color(0xFFF2F6FF); const Color backgroundColorDark = Color(0xFF25254B); const Color shadowColorLight = Color(0xFF4A5367); diff --git a/motula_translate_app/lib/screens/entryPoint/components/animated_bar.dart b/motula_translate_app/lib/screens/entryPoint/components/animated_bar.dart index 2818d1c..e71965a 100644 --- a/motula_translate_app/lib/screens/entryPoint/components/animated_bar.dart +++ b/motula_translate_app/lib/screens/entryPoint/components/animated_bar.dart @@ -16,7 +16,7 @@ class AnimatedBar extends StatelessWidget { height: 4, width: isActive ? 20 : 0, decoration: const BoxDecoration( - color: Color(0xFF81B4FF), + color: Color(0xFF1A6B18), borderRadius: BorderRadius.all( Radius.circular(12), )), diff --git a/motula_translate_app/lib/screens/entryPoint/components/side_bar.dart b/motula_translate_app/lib/screens/entryPoint/components/side_bar.dart index 566238d..ba63c1a 100644 --- a/motula_translate_app/lib/screens/entryPoint/components/side_bar.dart +++ b/motula_translate_app/lib/screens/entryPoint/components/side_bar.dart @@ -21,7 +21,7 @@ class _SideBarState extends State { width: 288, height: double.infinity, decoration: const BoxDecoration( - color: Color(0xFF17203A), + color: Color(0xFF1A6B18), borderRadius: BorderRadius.all( Radius.circular(30), ), diff --git a/motula_translate_app/lib/screens/entryPoint/components/side_menu.dart b/motula_translate_app/lib/screens/entryPoint/components/side_menu.dart index 489252e..cc67048 100644 --- a/motula_translate_app/lib/screens/entryPoint/components/side_menu.dart +++ b/motula_translate_app/lib/screens/entryPoint/components/side_menu.dart @@ -34,7 +34,7 @@ class SideMenu extends StatelessWidget { left: 0, child: Container( decoration: const BoxDecoration( - color: Color(0xFF6792FF), + color: Color(0xFFDF930B), borderRadius: BorderRadius.all(Radius.circular(10)), ), ), diff --git a/motula_translate_app/lib/screens/entryPoint/entry_point.dart b/motula_translate_app/lib/screens/entryPoint/entry_point.dart index 6138531..ebdf659 100644 --- a/motula_translate_app/lib/screens/entryPoint/entry_point.dart +++ b/motula_translate_app/lib/screens/entryPoint/entry_point.dart @@ -18,8 +18,7 @@ class EntryPoint extends StatefulWidget { State createState() => _EntryPointState(); } -class _EntryPointState extends State - with SingleTickerProviderStateMixin { +class _EntryPointState extends State with SingleTickerProviderStateMixin { bool isSideBarOpen = false; Menu selectedBottonNav = bottomNavItems.first; @@ -88,7 +87,7 @@ class _EntryPointState extends State offset: Offset(animation.value * 265, 0), child: Transform.scale( scale: scalAnimation.value, - child: const ClipRRect( + child: ClipRRect( borderRadius: BorderRadius.all( Radius.circular(24), ), diff --git a/motula_translate_app/lib/screens/home/components/words_screen.dart b/motula_translate_app/lib/screens/home/components/words_screen.dart index 96ff6fa..825da8a 100644 --- a/motula_translate_app/lib/screens/home/components/words_screen.dart +++ b/motula_translate_app/lib/screens/home/components/words_screen.dart @@ -17,7 +17,7 @@ class WordsScreen extends StatefulWidget { class _WordsScreenState extends State { Future fetchWord() async { final response = await http.get( - Uri.parse("https://5ddc-37-101-56-133.ngrok-free.app/api/words/tasto")); + Uri.parse("https://9152-37-101-56-133.ngrok-free.app/api/words/tasto")); if (response.statusCode == 200) { return Word.fromJson(jsonDecode(response.body)); @@ -32,12 +32,12 @@ class _WordsScreenState extends State { future: fetchWord(), builder: (context, snapshot) { if (snapshot.hasData) { - // Display the fetched joke when data is available - return Center(child: Text( + // Display the fetched Word when data is available + return Text( snapshot.data!.translation, - style: TextStyle(fontSize: 30, color: Colors.grey[800]) - ) - ); + style: const TextStyle(fontSize: 30, color: Color(0xFFFFFFFF),fontWeight: FontWeight.bold) + ); + } else if (snapshot.hasError) { // Display an error message if there's an error return Text('${snapshot.error}'); diff --git a/motula_translate_app/lib/screens/home/home_screen.dart b/motula_translate_app/lib/screens/home/home_screen.dart index 03e0616..978015d 100644 --- a/motula_translate_app/lib/screens/home/home_screen.dart +++ b/motula_translate_app/lib/screens/home/home_screen.dart @@ -5,7 +5,9 @@ import 'components/words_screen.dart'; class HomePage extends StatelessWidget { - const HomePage({super.key}); + HomePage({super.key}); + final TextEditingController _textHomepageContoller = TextEditingController(); + late List listaWidget; @override Widget build(BuildContext context) { @@ -22,15 +24,16 @@ class HomePage extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Image.asset('assets/icons/italy.png', width: 50, height: 50), + Image.asset('assets/icons/italy.png', width: 40, height: 40), const SizedBox(width: 20), Image.asset('assets/icons/next.png', width: 30, height:30), const SizedBox(width: 10), //Text(' --> ', style: TextStyle(fontSize: 30, color: Colors.grey[800])), - Image.asset('assets/icons/flagMottola.png', width: 64, height: 64), + Image.asset('assets/icons/flagMottola.png', width: 54, height: 54), ]), const SizedBox(height: 20), TextField( + controller: _textHomepageContoller, keyboardType: TextInputType.multiline, maxLines: null, style: TextStyle(fontSize: 20, color: Colors.grey[800]), @@ -40,20 +43,60 @@ class HomePage extends StatelessWidget { ), ), const SizedBox(height: 20), - ElevatedButton( - onPressed: () { - - }, - child: Text('Traduci'), - style: ElevatedButton.styleFrom( - backgroundColor: Colors.orange, - padding: const EdgeInsets.symmetric(horizontal: 50, vertical: 20), - textStyle: const TextStyle( - fontSize: 15, - fontWeight: FontWeight.bold)), + Container( + margin: const EdgeInsets.all(10.0), + width: 500, + height: 100, + decoration: BoxDecoration( + color: const Color(0x9121781C), + borderRadius: BorderRadius.circular(10.0), + ), + child: const Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + WordsScreen(), + //Align( + // alignment: Alignment.center, + // child: Text("ESEMPIO", + // style: TextStyle(fontSize: 30, color: Color(0xFFFFFFFF),fontWeight: FontWeight.bold)), + //), + ] + ), ), - const SizedBox(height: 30), - WordsScreen(), + const SizedBox(height: 20), + TextButton( + onPressed: () { + showDialog( + context: context, + builder: (context) { + if (_textHomepageContoller.text.isEmpty){ + return const AlertDialog( + + content: Text('Inserisci la parola italiana da tradurre', style: TextStyle(color: Color( + 0xFFFF0000), fontSize: 25, fontWeight: FontWeight.bold)), + ); + }else{ + //return AlertDialog( + // Retrieve the text the that user has entered by using the + // TextEditingController. + // content: Text(_textHomepageContoller.text), + //); + + return WordsScreen(); + } + }, + ); + }, + child: Text('Traduci'), + style: ElevatedButton.styleFrom( + backgroundColor: const Color(0xFFDF930B), + padding: const EdgeInsets.symmetric(horizontal: 30, vertical: 20), + textStyle: const TextStyle( + fontSize: 15, + fontWeight: FontWeight.bold)), + ), + //WordsScreen(), ], ), ),