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

@@ -17,7 +17,7 @@ class WordsScreen extends StatefulWidget {
class _WordsScreenState extends State<WordsScreen> {
Future<Word> 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<WordsScreen> {
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}');