Skip to content

Instantly share code, notes, and snippets.

@pxpc2
Created May 31, 2022 20:24
Show Gist options
  • Select an option

  • Save pxpc2/6be129a40afff41a6245f24d8a2b9ec0 to your computer and use it in GitHub Desktop.

Select an option

Save pxpc2/6be129a40afff41a6245f24d8a2b9ec0 to your computer and use it in GitHub Desktop.

Revisions

  1. pxpc2 created this gist May 31, 2022.
    49 changes: 49 additions & 0 deletions home.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    import 'dart:convert';
    import 'dart:ffi';

    import 'package:flutter/material.dart';
    import 'package:http/http.dart' as http;

    class Home extends StatefulWidget {
    const Home({Key? key}) : super(key: key);

    @override
    State<Home> createState() => _HomeState();
    }

    class _HomeState extends State<Home> {

    late String btcResponse;

    Future<Map> makeCall() async {
    const String url = "https://blockchain.info/ticker";
    http.Response response = await http.get(Uri.parse(url));
    return json.decode(response.body);
    }

    @override
    Widget build(BuildContext context) {
    return FutureBuilder<Map>(builder: (context, snapshot) {
    Widget futureChild;
    if (snapshot.hasData) {
    double value = snapshot.data!["BRL"]["buy"];
    futureChild = Text("BTC value in BRL is $value");
    } else if (snapshot.hasError) {
    futureChild = Text("Error has occured: ${snapshot.error}");
    } else {
    // waiting for data still
    print("waiting data");
    futureChild = const CircularProgressIndicator();
    }
    return Center(child: Scaffold(
    appBar: AppBar(title: Text("App"), backgroundColor: Colors.deepPurple,),
    body: Center(
    child: Padding(
    child: SingleChildScrollView(child: futureChild),
    padding: EdgeInsets.only(top: 60, bottom: 60),
    )
    ),
    ));
    }, future: makeCall());
    }
    }