-
Notifications
You must be signed in to change notification settings - Fork 114
/
main.dart
54 lines (46 loc) · 1.47 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import 'dart:async';
import 'dart:convert';
import 'package:amazon_cognito_identity_dart_2/sig_v4.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:secure_counter/screens/home_screen.dart';
class Counter {
int count;
Counter(this.count);
factory Counter.fromJson(json) {
return Counter(json['count']);
}
}
class CounterService {
AwsSigV4Client awsSigV4Client;
CounterService(this.awsSigV4Client);
/// Retrieve user's previous count from Lambda + DynamoDB
Future<Counter> getCounter() async {
final signedRequest =
SigV4Request(awsSigV4Client, method: 'GET', path: '/counter');
final response =
await http.get(signedRequest.url, headers: signedRequest.headers);
return Counter.fromJson(json.decode(response.body));
}
/// Increment user's count in DynamoDB
Future<Counter> incrementCounter() async {
final signedRequest =
SigV4Request(awsSigV4Client, method: 'PUT', path: '/counter');
final response =
await http.put(signedRequest.url, headers: signedRequest.headers);
return Counter.fromJson(json.decode(response.body));
}
}
void main() => runApp(SecureCounterApp());
class SecureCounterApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Cognito on Flutter',
theme: ThemeData(
primarySwatch: Colors.orange,
),
home: HomePage(title: 'Cognito on Flutter'),
);
}
}