Handled Exception In Future Builder
Step 1
We cannot directly remove the time stamp from Handled Exception In Future Builder but using the intl.dart package we can easily filter the date stamp from time stamp. So open your flutter project’s pubspec.yaml in code .
dependencies: flutter: sdk: flutter http: ^0.12.1
flutter pub get
import 'dart:async'; import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:flutter/material.dart'; void main() => runApp(new MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: MyHomePage(), ); } } class MyHomePage extends StatefulWidget { final String title; MyHomePage({this.title}); @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { final String uri = 'https://jsonplaceholder.typicode.com/users_err'; //intentional error Future<String> _errorFuture() async { var response = await http.get(uri); if (response.statusCode == 200) { final items = json.decode(response.body).cast<Map<String, dynamic>>(); String string = items.first; return string; } else { throw Exception('Failed to load internet'); } } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Colors.amber, title: Text("Exception in FutureBuilder")), body: FutureBuilder<String>( future: _errorFuture(), builder: (context, snapshot) { if (snapshot.hasError) { return Center( child: Text( "ERROR: " + snapshot.error.toString(), ), ); } return Text(snapshot.data); }, ), ); } }