skip to Main Content

Flutter – Exception handling inside FutureBuilder

import 'package:flutter/material.dart'; void main() { runApp(const MainApp()); } class MainApp extends StatelessWidget { const MainApp({super.key}); Future<void> _initialize() async { await Future.delayed(const Duration(seconds: 2)); try { throw Exception("Error"); } catch (e) {} } @override Widget build(BuildContext context) { return MaterialApp( home:…

VIEW QUESTION

Future API Call Flutter

Im trying to create an simple Network class on dart, to centralize all my calls to an specific API. So i create an Service class, and create an mock and a get function using Dio. import 'package:dio/dio.dart'; import 'package:flutter/services.dart'; import…

VIEW QUESTION

how to execute two asynchronous functions with flutter?

I have two functions in flutter. the first one is belManager.writeCharacteristic and the second one is belManager.disonnect I want to execute belManager.disonnect() after belManager.writeCharacteristic is completed. However for some reason bleManager.disonenct() is called before belManager.writeCharacteristic is completed. this is the…

VIEW QUESTION

setState not updating my star color because the FutureBuilder keeps rebuilding whenever I call setState – Flutter

Positioned( top: 12, right: 12, child: SizedBox( height: 25, width: 25, child: CircleAvatar( backgroundColor: isGolden? Colors.amber :Colors.black87, child: IconButton( padding: EdgeInsets.zero, icon: Icon(Icons.star,), color: Color(0xFFFFFFD5), onPressed: (){ futureMessage = PostStoryFavoriteCreateDelete(snapshot.data!.data![index].id.toString()); ScaffoldMessenger.of(context).showSnackBar(SnackBar(elevation: 20,content: FutureBuilder( future: futureMessage, builder: (context, snapshot){ if (snapshot.hasData)…

VIEW QUESTION

Future not returning String – Flutter

Why do I keep getting 'Instance of...' when I'm trying to get a String. What's wrong with the function? Future<string?> counter() async { Future.delayed(const Duration(seconds: 5), () { context.watch<FoodCount>().display(widget.food).toString(); return widget.food.quantity.toString(); }); int count = widget.food.quantity; // print(count); return count;…

VIEW QUESTION
Back To Top
Search