-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flutter com web API: integrando sua app mobile
- Loading branch information
Showing
15 changed files
with
445 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"sqflite","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.1.7+2\\\\","dependencies":[]}],"android":[{"name":"sqflite","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.1.7+2\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"sqflite","dependencies":[]}],"date_created":"2020-07-28 09:43:34.384780","version":"1.17.5"} | ||
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"http_interceptor","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\http_interceptor-0.1.1\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.1.7+2\\\\","dependencies":[]}],"android":[{"name":"http_interceptor","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\http_interceptor-0.1.1\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.1.7+2\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"http_interceptor","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-07-28 09:47:41.675852","version":"1.17.5"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class CenteredMessage extends StatelessWidget { | ||
final String message; | ||
final IconData icon; | ||
final double iconSize; | ||
final double fontSize; | ||
|
||
CenteredMessage( | ||
this.message, { | ||
this.icon, | ||
this.iconSize = 64, | ||
this.fontSize = 24, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
children: <Widget>[ | ||
Visibility( | ||
child: Icon( | ||
icon, | ||
size: iconSize, | ||
), | ||
visible: icon != null, | ||
), | ||
Padding( | ||
padding: const EdgeInsets.only(top: 24.0), | ||
child: Text( | ||
message, | ||
style: TextStyle(fontSize: fontSize), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class Progress extends StatelessWidget { | ||
|
||
final String message; | ||
|
||
Progress({this.message = 'Loading'}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
children: <Widget>[ | ||
CircularProgressIndicator(), | ||
Text(message) | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'package:http_interceptor/http_interceptor.dart'; | ||
|
||
class LoggingInterceptor implements InterceptorContract { | ||
@override | ||
Future<RequestData> interceptRequest({RequestData data}) async { | ||
print('Request'); | ||
print('url: ${data.requestUrl}'); | ||
print('headers: ${data.headers}'); | ||
print('body: ${data.body}'); | ||
return data; | ||
} | ||
|
||
@override | ||
Future<ResponseData> interceptResponse({ResponseData data}) async { | ||
print('Response'); | ||
print('status code: ${data.statusCode}'); | ||
print('headers: ${data.headers}'); | ||
print('body: ${data.body}'); | ||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:http/http.dart'; | ||
import 'package:http_interceptor/http_interceptor.dart'; | ||
|
||
import 'interceptors/logging_interceptor.dart'; | ||
|
||
final Client client = HttpClientWithInterceptor.build( | ||
interceptors: [LoggingInterceptor()], | ||
); | ||
|
||
const String baseUrl = 'http://192.168.20.249:8080/transactions'; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:bytebank/http/webclient.dart'; | ||
import 'package:bytebank/models/transaction.dart'; | ||
import 'package:http/http.dart'; | ||
|
||
class TransactionWebClient { | ||
Future<List<Transaction>> findAll() async { | ||
final Response response = | ||
await client.get(baseUrl).timeout(Duration(seconds: 5)); | ||
final List<dynamic> decodedJson = jsonDecode(response.body); | ||
return decodedJson | ||
.map((dynamic json) => Transaction.fromJson(json)) | ||
.toList(); | ||
} | ||
|
||
Future<Transaction> save(Transaction transaction) async { | ||
final String transactionJson = jsonEncode(transaction.toJson()); | ||
|
||
final Response response = await client.post(baseUrl, | ||
headers: { | ||
'Content-type': 'application/json', | ||
'password': '1000', | ||
}, | ||
body: transactionJson); | ||
|
||
return Transaction.fromJson(jsonDecode(response.body)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'contact.dart'; | ||
|
||
class Transaction { | ||
final double value; | ||
final Contact contact; | ||
|
||
Transaction( | ||
this.value, | ||
this.contact, | ||
); | ||
|
||
Transaction.fromJson(Map<String, dynamic> json) : | ||
value = json['value'], | ||
contact = Contact.fromJson(json['contact']); | ||
|
||
Map<String, dynamic> toJson() => | ||
{ | ||
'value': value, | ||
'contact': contact.toJson(), | ||
}; | ||
|
||
@override | ||
String toString() { | ||
return 'Transaction{value: $value, contact: $contact}'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.