Skip to content

Instantly share code, notes, and snippets.

@jonahwilliams
Created March 12, 2018 19:54
Show Gist options
  • Save jonahwilliams/c60d0d9108ddcc0b775991f66428b563 to your computer and use it in GitHub Desktop.
Save jonahwilliams/c60d0d9108ddcc0b775991f66428b563 to your computer and use it in GitHub Desktop.
FutureBuilder
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
void main() {
runApp(new MaterialApp(home: new NewTransactionPage()));
}
class NewTransactionPage extends StatefulWidget {
@override
State createState() => new _NewTransactionPageState();
}
class _NewTransactionPageState extends State<NewTransactionPage> {
@override
Widget build(BuildContext context) {
final Future<Null> futureParticipants = new Future<Null>.delayed(new Duration(seconds: 2));
return new Scaffold(
appBar: new AppBar(
title: const Text('Add transaction'),
),
body: new FutureBuilder<Null>(
future: futureParticipants,
builder: (BuildContext context, AsyncSnapshot<List<Map>> snapshot) {
if (snapshot.connectionState != ConnectionState.done)
return const Text('Loading...');
return
new DropdownButton<int>(
items: [1, 2, 3]
.map((int row) => new DropdownMenuItem<int>(
value: row,
child: const Text('lol')))
.toList(),
onChanged: (int value) {
print('selected $value');
},
);
},
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment