Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:convert';
- import 'package:jaguar_serializer/jaguar_serializer.dart';
- import 'package:flutter/material.dart';
- import 'package:http/http.dart' as http;
- void main() => runApp(App());
- List<int> welcomeFromJson(String str) => new List<int>.from(json.decode(str).map((x) => x));
- String welcomeToJson(List<int> data) => json.encode(new List<dynamic>.from(data.map((x) => x)));
- class App extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Flutter Demo',
- theme: ThemeData(
- primarySwatch: Colors.blue,
- ),
- home: HomePage(),
- );
- }
- }
- class HomePage extends StatefulWidget {
- @override
- _HomePageState createState() => _HomePageState();
- }
- class _HomePageState extends State<HomePage> {
- //Note _currentUser;
- Future<List<int>> fetchNotes() async {
- final String Uri = 'https://fbayub.000webhostapp.com/d.json';
- /*https://fbayub.000webhostapp.com/nim.json
- https://raw.githubusercontent.com/boriszv/json/master/random_example.json
- https://fbayub.000webhostapp.com/d.json
- https://jsonplaceholder.typicode.com/users*/
- var response = await http.get(Uri);
- if (response.statusCode == 200) {
- final items = json.decode(response.body).cast<Map<String, dynamic>>();
- List<int> conith = new List();
- conith = new List<int>.from(items.map((x)=>x));
- return conith;
- //throw Exception('Failed to load internet');
- }
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text('Flutter listview with json'),
- ),
- body: Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- mainAxisSize: MainAxisSize.max,
- children: <Widget>[
- FutureBuilder<List<int>>(
- future: fetchNotes(),
- builder:
- (BuildContext context, AsyncSnapshot<List<int>> snapshot) {
- if (!snapshot.hasData) return CircularProgressIndicator();
- return DropdownButton<int>(
- items: snapshot.data
- .map((user) => DropdownMenuItem<int>(
- child: Text(user.toString()),
- value: user,
- ))
- .toList(),
- onChanged: (int value) {
- setState(() {});
- },
- isExpanded: false,
- //value: ???,
- hint: Text('Select User'),
- );
- }),
- SizedBox(height: 20.0),
- /* ??? != null
- ? Text("NIM : " +???)
- : Text("No NIM selected"),*/
- ],
- ),
- ),
- );
- }
- }
- /*class Note {
- int id;
- String name;
- String username;
- String email;
- Note(this.id, this.name,this.username, this.email);
- Note.fromJson(Map<String, dynamic> json) {
- id = json['id'];
- name = json['name'];
- email= json['email'];
- username= json['username'];
- }
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement