Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
void main() => runApp(MaterialApp(
home: HomeScreen(),
class HomeScreen extends StatefulWidget {
_HomeScreenState createState() => _HomeScreenState();
class _HomeScreenState extends State<HomeScreen> {
String _baseUrl = "";
String _valProvince;
List<dynamic> _dataProvince = List();
void getProvince() async {
final respose = await http.get(_baseUrl + "getProvince1"); //untuk melakukan request ke webservice
var listData = jsonDecode(respose.body); //lalu kita decode hasil datanya
setState(() {
_dataProvince = listData; // dan kita set kedalam variable _dataProvince
print("data : $listData");
void initState() {
// TODO: implement initState
getProvince(); //Ketika pertama kali membuka home screen makan method ini dijalankan untuk pertama kalinya juga
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Dropdown Menu Button JSON")),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
hint: Text("Select Province"),
value: _valProvince,
items: {
return DropdownMenuItem(
child: Text(item['province']),
value: item['province'],
onChanged: (value) {
setState(() {
_valProvince = value;
"Kamu memilih provinsi $_valProvince",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment