modify layout and add function to print error and text translate

This commit is contained in:
paoloGuagnano
2024-03-29 17:17:40 +01:00
parent 4a6fbaf313
commit f9b8434ddf
7 changed files with 71 additions and 29 deletions

View File

@@ -1,6 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
const Color backgroundColor2 = Color(0xFF17203A); const Color backgroundColor2 = Color(0xFFDF930B);
const Color backgroundColorLight = Color(0xFFF2F6FF); const Color backgroundColorLight = Color(0xFFF2F6FF);
const Color backgroundColorDark = Color(0xFF25254B); const Color backgroundColorDark = Color(0xFF25254B);
const Color shadowColorLight = Color(0xFF4A5367); const Color shadowColorLight = Color(0xFF4A5367);

View File

@@ -16,7 +16,7 @@ class AnimatedBar extends StatelessWidget {
height: 4, height: 4,
width: isActive ? 20 : 0, width: isActive ? 20 : 0,
decoration: const BoxDecoration( decoration: const BoxDecoration(
color: Color(0xFF81B4FF), color: Color(0xFF1A6B18),
borderRadius: BorderRadius.all( borderRadius: BorderRadius.all(
Radius.circular(12), Radius.circular(12),
)), )),

View File

@@ -21,7 +21,7 @@ class _SideBarState extends State<SideBar> {
width: 288, width: 288,
height: double.infinity, height: double.infinity,
decoration: const BoxDecoration( decoration: const BoxDecoration(
color: Color(0xFF17203A), color: Color(0xFF1A6B18),
borderRadius: BorderRadius.all( borderRadius: BorderRadius.all(
Radius.circular(30), Radius.circular(30),
), ),

View File

@@ -34,7 +34,7 @@ class SideMenu extends StatelessWidget {
left: 0, left: 0,
child: Container( child: Container(
decoration: const BoxDecoration( decoration: const BoxDecoration(
color: Color(0xFF6792FF), color: Color(0xFFDF930B),
borderRadius: BorderRadius.all(Radius.circular(10)), borderRadius: BorderRadius.all(Radius.circular(10)),
), ),
), ),

View File

@@ -18,8 +18,7 @@ class EntryPoint extends StatefulWidget {
State<EntryPoint> createState() => _EntryPointState(); State<EntryPoint> createState() => _EntryPointState();
} }
class _EntryPointState extends State<EntryPoint> class _EntryPointState extends State<EntryPoint> with SingleTickerProviderStateMixin {
with SingleTickerProviderStateMixin {
bool isSideBarOpen = false; bool isSideBarOpen = false;
Menu selectedBottonNav = bottomNavItems.first; Menu selectedBottonNav = bottomNavItems.first;
@@ -88,7 +87,7 @@ class _EntryPointState extends State<EntryPoint>
offset: Offset(animation.value * 265, 0), offset: Offset(animation.value * 265, 0),
child: Transform.scale( child: Transform.scale(
scale: scalAnimation.value, scale: scalAnimation.value,
child: const ClipRRect( child: ClipRRect(
borderRadius: BorderRadius.all( borderRadius: BorderRadius.all(
Radius.circular(24), Radius.circular(24),
), ),

View File

@@ -17,7 +17,7 @@ class WordsScreen extends StatefulWidget {
class _WordsScreenState extends State<WordsScreen> { class _WordsScreenState extends State<WordsScreen> {
Future<Word> fetchWord() async { Future<Word> fetchWord() async {
final response = await http.get( 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) { if (response.statusCode == 200) {
return Word.fromJson(jsonDecode(response.body)); return Word.fromJson(jsonDecode(response.body));
@@ -32,12 +32,12 @@ class _WordsScreenState extends State<WordsScreen> {
future: fetchWord(), future: fetchWord(),
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.hasData) { if (snapshot.hasData) {
// Display the fetched joke when data is available // Display the fetched Word when data is available
return Center(child: Text( return Text(
snapshot.data!.translation, 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) { } else if (snapshot.hasError) {
// Display an error message if there's an error // Display an error message if there's an error
return Text('${snapshot.error}'); return Text('${snapshot.error}');

View File

@@ -5,7 +5,9 @@ import 'components/words_screen.dart';
class HomePage extends StatelessWidget { class HomePage extends StatelessWidget {
const HomePage({super.key}); HomePage({super.key});
final TextEditingController _textHomepageContoller = TextEditingController();
late List<WordsScreen> listaWidget;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -22,15 +24,16 @@ class HomePage extends StatelessWidget {
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ 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), const SizedBox(width: 20),
Image.asset('assets/icons/next.png', width: 30, height:30), Image.asset('assets/icons/next.png', width: 30, height:30),
const SizedBox(width: 10), const SizedBox(width: 10),
//Text(' --> ', style: TextStyle(fontSize: 30, color: Colors.grey[800])), //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), const SizedBox(height: 20),
TextField( TextField(
controller: _textHomepageContoller,
keyboardType: TextInputType.multiline, keyboardType: TextInputType.multiline,
maxLines: null, maxLines: null,
style: TextStyle(fontSize: 20, color: Colors.grey[800]), style: TextStyle(fontSize: 20, color: Colors.grey[800]),
@@ -40,20 +43,60 @@ class HomePage extends StatelessWidget {
), ),
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
ElevatedButton( 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: 20),
TextButton(
onPressed: () { 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'), child: Text('Traduci'),
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: Colors.orange, backgroundColor: const Color(0xFFDF930B),
padding: const EdgeInsets.symmetric(horizontal: 50, vertical: 20), padding: const EdgeInsets.symmetric(horizontal: 30, vertical: 20),
textStyle: const TextStyle( textStyle: const TextStyle(
fontSize: 15, fontSize: 15,
fontWeight: FontWeight.bold)), fontWeight: FontWeight.bold)),
), ),
const SizedBox(height: 30), //WordsScreen(),
WordsScreen(),
], ],
), ),
), ),