Skip to content

Instantly share code, notes, and snippets.

@malibayram
Created December 15, 2020 16:03
Show Gist options
  • Save malibayram/c49007f5b2cce95b1973be1744d2de4b to your computer and use it in GitHub Desktop.
Save malibayram/c49007f5b2cce95b1973be1744d2de4b to your computer and use it in GitHub Desktop.
import 'dart:convert';
import 'package:flutter/material.dart';
main() => runApp(MaterialApp(home: LocalJsonKonusu()));
class LocalJsonKonusu extends StatefulWidget {
@override
State<StatefulWidget> createState() => LocaleState();
}
class LocaleState extends State<LocalJsonKonusu> {
List ogrenci;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Local Json Konusu"),
),
body: Container(
padding: EdgeInsets.all(20.0),
child: Center(
child: FutureBuilder(
future: DefaultAssetBundle.of(context)
.loadString("assets/veriler/sinif.json"),
builder: (context, cevap) {
ogrenci = jsonDecode(cevap.data
.toString());
return ListView.builder(
itemBuilder: (BuildContext context, int index) {
return Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text("Adı: " + ogrenci[index]['adi']),
Text("Soyadı: " + ogrenci[index]['soyadi']),
Text("Cinsiyet: " + ogrenci[index]['cinsiyet']),
],
),
);
},
itemCount: ogrenci == null
? 0
: ogrenci
.length,
);
},
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment