04-Module 4
04-Module 4
Mobile Programming
MODULE 4:
Flutter App Lifecycle and
Internet Access
Module 4
2
Flutter App Lifecycle
3
Flutter
App
Lifecyle
4
App Lifecycle States in Flutter
Flutter App
Lifecyle
App Lifecycle States in Flutter
Flutter App
Lifecyle
App Lifecycle States in Flutter
13
WebView
WebView for Flutter
14
WebView
WebView for Flutter
https://codelabs.developers.google.com/codel
abs/flutter-webview#0
15
Cloud Services: Pros and Cons
16
Pros and Cons of Cloud Services
***
▪ Advantages
▪ Disaster Recovery (DR)
▪ Access your data anywhere
▪ Low cost
▪ Scalability
▪ Security
▪ Disadvantage
▪ Lack of total control
▪ Difficult to migrate
▪ Requires Internet
▪ Privacy
▪ Long-term contracts
17
REST APIS:
Using Dio and Retrofit
18
HTTP client
Dio
• Dio is a robust HTTP client for Dart that provides a standard way to
make HTTP requests and manage responses.
19
HTTP client
Dio
20
HTTP client
Dio
21
HTTP client
Dio
22
Making Simple GET Requests with Dio
Dio
import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
class User {
final int id;
final String name;
23
Making Simple GET Requests with Dio
Dio
dependencies:
dio: ^5.3.0
24
Making Simple GET Requests with Dio
Dio
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Dio Example')),
body: ListView.builder(
itemCount: users.length,
itemBuilder: (context, index) {
return ListTile(title: Text(users[index].name));
},
),
);
}
}
void main() {
runApp(MaterialApp(home: DioExample()));
}
25
Making Simple GET Requests with Dio
Dio
@override
void initState() {
super.initState();
fetchUsers();
}
26
Making Simple GET Requests with Dio
Dio
setState(() {
users = jsonData.map((user) => User.fromJson(user)).toList();
});
} catch (e) {
print('Error fetching users: $e');
}
}
27
Making Simple GET Dio
Requests with Dio
28
REST API
Retrofit
• It was created by Square, you can also use retrofit to receive data
structures other than JSON, for example SimpleXML and Jackson
• Retrofit is a Dio client that makes consuming Rest APIs easier for
Flutter applications
29
How to call Rest APIs in
Flutter
30
How to call Rest APIs in Flutter
Steps
• Dio is a robust HTTP client for Dart that provides a standard way to
make HTTP requests and manage responses.
Tutorial Link
https://medium.com/mindful-engineering/retrofit-the-easiest-way-to-call-
rest-apis-is-flutter-fe55d1e7c5c2
31
End of Module 4