Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

json in listview flutter

Future<Post> fetchPost() async {
  final response =
  await http.get('http://simone.fabriziolerose.it/index.php/Hello/dispdataflutter');

  if (response.statusCode == 200) {
    // If the call to the server was successful, parse the JSON.
    return Post.fromJson(json.decode(response.body));
  } else {
    // If that call was not successful, throw an error.
    throw Exception('Failed to load post');
  }
}

class Post {
  final int id;
  final String title;
  final String body;

  Post({ this.id, this.title, this.body});

  factory Post.fromJson(Map<String, dynamic> json) {
    return Post(

      id: json['id'],
      title: json['testo'],
      body: json['stato'],
    );
  }
}

void main() => runApp(MyApp(post: fetchPost()));

class MyApp extends StatelessWidget {
  final Future<Post> post;

  MyApp({Key key, this.post}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Fetch Data Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text('Fetch Data Example'),
        ),
        body: Center(
          child: FutureBuilder<Post>(
            future: post,
            builder: (context, snapshot) {
              if (snapshot.hasData) {
                return Text(snapshot.data.title);
              } else if (snapshot.hasError) {
                return Text("${snapshot.error}");
              }

              // By default, show a loading spinner.
              return CircularProgressIndicator();
            },
          ),
        ),
      ),
    );
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: bodyparser express deprecated 
Javascript :: javascript cartesian product 
Javascript :: each jquery 
Javascript :: how to add cdn link in shopify 
Javascript :: how to show calendar in javascript 
Javascript :: return object list in find js 
Javascript :: timeout angularjs 
Javascript :: animated node with tag 2 does not exist 
Javascript :: js get integer value of 
Javascript :: javascript array to string with commas 
Javascript :: jquery find element before 
Javascript :: js connect to websocket 
Javascript :: conditional props react 
Javascript :: simple js drawing program 
Javascript :: array map javascript 
Javascript :: angular how to check a radiobox 
Javascript :: javascript disable div 
Javascript :: javascript get client page title 
Javascript :: test if value is function 
Javascript :: javascript convert number to spreadsheet column 
Javascript :: share to gmail from website 
Javascript :: months js 
Javascript :: replace is not working in javascript 
Javascript :: latitude longitude to km javascript 
Javascript :: js while continue 
Javascript :: check if variable is set javascript 
Javascript :: jquery ui timepicker 
Javascript :: jquery document ready shorthand 
Javascript :: configuration react-router-dom v6 
Javascript :: emoji-picker-react 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =