tutorial
Ctrlk
  • About
  • Flutter web
  • My Note
    • Cara mudah setting Firebase
    • solusi text overflow
    • Setting Firebase Mobile
    • Setting MinSDK Android
    • Run build runner
    • Load Json FromAsset
    • Set Height TabBar
    • WillPopScope
    • Dropdown with null
    • Interview Flutter
    • shortcut android studio
    • Build with different main.dart
    • Validating email
    • search delay
    • Hive
    • penggunaan sort maupun func lain
    • incompatible version of Kotlin.
    • Google Signin error
    • add Map to Map
    • Cors Anywhere
    • run scrcpy simple
    • android studio adb server version (41) doesn't match this client (39); killing
    • Connect adb with hotspot
    • Bloc , intinya...
    • Restorable state
    • Custom Theme DatePicker Flutter
    • membungkus widget dengan tema
    • All About Extention
    • Provider watch read
    • Provider , App works in debug mode but does not work in release mode
    • make extention
    • Sliver app bar
    • Custom Error screen
    • Rename Package
    • error build on AndroidStudio from vscode
    • add tooltip to all widget
    • Textformfield validator
    • Membuat String Rupiah
    • Sort List Dart
    • chart
    • membuat Date time lokal
    • Change default PageTransition
    • Show Hide Password
    • Error UserFriendly
    • Responsive adaptive layout
    • Tips SingleScrollingView
    • Build context
    • FittedBox
    • validation
    • alertDialog
    • Set package in VS Code when creating a project
  • Usefull source
    • Setting JAVA_HOME
    • Tools for Flutter
    • WEBVIEW
    • membuat Marque
    • LazyLoad
    • Tips
    • List article
    • List Web Complete Tutorial
    • List library
    • Parsing nested Json
    • Future
    • Flutter Sample HTTP Request Github with https://reqres.in/
    • Const vs Final
    • Constructor
    • Function
    • Font
    • CRUD
    • Key
    • Free bootcamp
    • State Manajement
  • Widgets
    • Top 5 Box widget
    • Framework library
    • kumpulan widget
    • Deep Dive
  • Interview Question
    • Kumpulan Pertannyaan Interview
  • kasus dari stackoverflow
    • Text Red in Hero
    • firebase issued
    • Untitled
  • library
    • Rapido
    • autoscroll text
Powered by GitBook
On this page
  1. Usefull source

Parsing nested Json

LogoImplement a Flutter ListView using data from a REST API - Melvin Dave Vivas Tech BlogImplement a Flutter ListView using data from a REST API - Melvin Dave Vivas Tech Blog
tutorial asli
tutorial asli tanpa nest json
format json tanpa nest

hasil edit

untuk array 'data'
sample Json data
sample hasil
https://www.udemy.com/course/learn-flutter-dart-to-build-ios-android-apps/learn/lecture/15103244?start=386#bookmarkswww.udemy.com
dapat solusi dari sini :)

PreviousList libraryNextFuture

Last updated 5 years ago

Was this helpful?

Was this helpful?

import 'dart:async';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

class Job {
  final String position;
  final String company;
  final String description;

  Job({this.position, this.company, this.description});

  factory Job.fromJson(Map<String, dynamic> json) {
    return Job(
      position: json['nama'],
      company: json['kontingen'],
      description: json['kelamin'],
    );
  }
}

class JobsListView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Column(
          children: <Widget>[
            Container(
              child: Text('ok'),
            ),
            Expanded(
              child: FutureBuilder<List<Job>>(
                future: _fetchJobs(),
                builder: (context, snapshot) {
                  if (snapshot.hasData) {
                    List<Job> data = snapshot.data;
                    return _jobsListView(data);
                  } else if (snapshot.hasError) {
                    return Text("${snapshot.error}");
                  }
                  return CircularProgressIndicator();
                },
              ),
            ),
          ],
        ),
      ),
    );
  }

  Future<List<Job>> _fetchJobs() async {
    final jobsListAPIUrl = 'http://dwirudi.com/skc/public/list_peserta';
//    final jobsListAPIUrl = 'https://mock-json-service.glitch.me/';
    final response = await http.get(jobsListAPIUrl);

    if (response.statusCode == 200) {
      List jsonResponse = json.decode(response.body)['data'];
      return jsonResponse.map((job) => new Job.fromJson(job)).toList();
    } else {
      throw Exception('Failed to load jobs from API');
    }
  }

  ListView _jobsListView(data) {
    return ListView.builder(
        itemCount: data.length,
        itemBuilder: (context, index) {
          return _tile(data[index].position, data[index].company, Icons.work);
        });
  }

  ListTile _tile(String title, String subtitle, IconData icon) => ListTile(
        title: Text(title,
            style: TextStyle(
              fontWeight: FontWeight.w500,
              fontSize: 20,
            )),
        subtitle: Text(subtitle),
        leading: Icon(
          icon,
          color: Colors.blue[500],
        ),
      );
}