You are on page 1of 2

import 'package:flutter/material.

dart';
import 'dart:convert';
import 'package:http/http.dart' as http;

void main() { runApp(MyApp());


}

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(debugShowCheckedModeBanner: false,
title: 'FLutter to Python',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Home(),
);
}
}

class Home extends StatefulWidget {


@override
HomeState createState() => HomeState();
}

class HomeState extends State<Home> {


String greetings = '';

@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text(greetings,
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),

Center(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
child: Text('<<'),
onPressed: decrementCounter,
),
Container(width: 10.0,),
RaisedButton(
child: Text(greetings),
onPressed: () async {

final response = await


http.get(Uri.parse('http://127.0.0.1:5000/'));

final decoded = json.decode(response.body) as Map<String,


dynamic>;

setState((){
greetings = decoded['greetings'];
});
},
),
]
)
],

),
),
);
}
}

You might also like