0% found this document useful (0 votes)
21 views2 pages

Python To Flutter

The document shows code for a Flutter app that makes an HTTP request to a Python backend and displays the response. The app contains a Home widget that makes the request and updates the greetings text when the response is received.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

Python To Flutter

The document shows code for a Flutter app that makes an HTTP request to a Python backend and displays the response. The app contains a Home widget that makes the request and updates the greetings text when the response is received.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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