Skip to content

Instantly share code, notes, and snippets.

@PeterHdd
Created January 13, 2020 18:08
Show Gist options
  • Save PeterHdd/896fa75be39ef3abab49f77b2a6855f5 to your computer and use it in GitHub Desktop.
Save PeterHdd/896fa75be39ef3abab49f77b2a6855f5 to your computer and use it in GitHub Desktop.
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
// Get Data
Future<bool> getCurrentUser() async {
return Future.delayed(Duration(seconds: 2), () => true,);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title : Text(widget.title)
),
body : FutureBuilder<bool>(
future: getCurrentUser(),
builder: (context, AsyncSnapshot<bool> snapshot) {
print("snapshot data");
Text(snapshot.hasData.toString());
if (snapshot.hasData) {
return Text(snapshot.data.toString());
}
else if(snapshot.data == false)
{
return Text("sdgsdf");
}
// By default, show a loading spinner.
return CircularProgressIndicator();
}));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment