Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.15 KB | None | 0 0
  1. import 'dart:convert';
  2. import 'package:jaguar_serializer/jaguar_serializer.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:http/http.dart' as http;
  5. void main() => runApp(App());
  6. List<int> welcomeFromJson(String str) => new List<int>.from(json.decode(str).map((x) => x));
  7.  
  8. String welcomeToJson(List<int> data) => json.encode(new List<dynamic>.from(data.map((x) => x)));
  9.  
  10. class App extends StatelessWidget {
  11.   @override
  12.   Widget build(BuildContext context) {
  13.     return MaterialApp(
  14.       title: 'Flutter Demo',
  15.       theme: ThemeData(
  16.         primarySwatch: Colors.blue,
  17.       ),
  18.       home: HomePage(),
  19.     );
  20.   }
  21. }
  22.  
  23. class HomePage extends StatefulWidget {
  24.   @override
  25.   _HomePageState createState() => _HomePageState();
  26. }
  27.  
  28. class _HomePageState extends State<HomePage> {
  29.   //Note _currentUser;
  30.   Future<List<int>> fetchNotes() async {
  31.     final String Uri = 'https://fbayub.000webhostapp.com/d.json';
  32.     /*https://fbayub.000webhostapp.com/nim.json
  33.     https://raw.githubusercontent.com/boriszv/json/master/random_example.json
  34.     https://fbayub.000webhostapp.com/d.json
  35.     https://jsonplaceholder.typicode.com/users*/
  36.     var response = await http.get(Uri);
  37.     if (response.statusCode == 200) {
  38.       final items = json.decode(response.body).cast<Map<String, dynamic>>();
  39.       List<int> conith = new List();
  40.       conith = new List<int>.from(items.map((x)=>x));
  41.         return conith;
  42.       //throw Exception('Failed to load internet');
  43.     }
  44.   }
  45.  
  46.   @override
  47.   Widget build(BuildContext context) {
  48.     return Scaffold(
  49.       appBar: AppBar(
  50.         title: Text('Flutter listview with json'),
  51.       ),
  52.       body: Center(
  53.         child: Column(
  54.           mainAxisAlignment: MainAxisAlignment.center,
  55.           mainAxisSize: MainAxisSize.max,
  56.           children: <Widget>[
  57.             FutureBuilder<List<int>>(
  58.                 future: fetchNotes(),
  59.                 builder:
  60.                     (BuildContext context, AsyncSnapshot<List<int>> snapshot) {
  61.                   if (!snapshot.hasData) return CircularProgressIndicator();
  62.                   return DropdownButton<int>(
  63.                     items: snapshot.data
  64.                         .map((user) => DropdownMenuItem<int>(
  65.                               child:  Text(user.toString()),
  66.                               value:  user,
  67.                             ))
  68.                         .toList(),
  69.                     onChanged: (int value) {
  70.                       setState(() {});
  71.                     },
  72.                     isExpanded: false,
  73.                     //value: ???,
  74.                     hint: Text('Select User'),
  75.                   );
  76.                 }),
  77.             SizedBox(height: 20.0),
  78.            /* ??? != null
  79.                 ? Text("NIM : " +???)
  80.                 : Text("No NIM selected"),*/
  81.           ],
  82.         ),
  83.       ),
  84.     );
  85.   }
  86. }
  87.  
  88. /*class Note {
  89.   int id;
  90.   String name;
  91.   String username;
  92.   String email;
  93.  
  94.   Note(this.id, this.name,this.username, this.email);
  95.  
  96.   Note.fromJson(Map<String, dynamic> json) {
  97.     id = json['id'];
  98.     name = json['name'];
  99.       email= json['email'];
  100.       username= json['username'];
  101.   }
  102. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement