Первая часть для AWS LAMbda
Вы можете использовать пакет https://pub.dev/packages/amazon_cognito_identity_dart
Аутентифицированный доступ для API Gateway + Lambda см.
https://github.com/jonsaw/amazon-cognito-identity-dart/#for-api-gateway--lambda
фрагмент кода
import 'package:http/http.dart' as http;
import 'package:amazon_cognito_identity_dart/cognito.dart';
import 'package:amazon_cognito_identity_dart/sig_v4.dart';
void main() async {
final credentials = new CognitoCredentials(
'ap-southeast-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', userPool);
await credentials.getAwsCredentials(session.getIdToken().getJwtToken());
const endpoint =
'https://xxxx.execute-api.ap-southeast-1.amazonaws.com/dev';
final awsSigV4Client = new AwsSigV4Client(
credentials.accessKeyId, credentials.secretAccessKey, endpoint,
sessionToken: credentials.sessionToken,
region: 'ap-southeast-1');
final signedRequest = new SigV4Request(awsSigV4Client,
method: 'POST',
path: '/projects',
headers: new Map<String, String>.from(
{'header-1': 'one', 'header-2': 'two'}),
queryParams: new Map<String, String>.from({'tracking': 'x123'}),
body: new Map<String, dynamic>.from({'color': 'blue'}));
http.Response response;
try {
response = await http.post(
signedRequest.url,
headers: signedRequest.headers, body: signedRequest.body);
} catch (e) {
print(e);
}
print(response.body);
}
Вторая часть строки ответа на загрузку webview_flutter
С помощью webViewController вы можете использовать controller.loadUrl
Вы можете скопировать приведенный ниже демо-код полного кода
фрагмент кода
WebView(
initialUrl: 'abc',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller = webViewController;
_loadHtmlFromString();
},
),
_controller.loadUrl( Uri.dataFromString(
fileText,
mimeType: 'text/html',
encoding: Encoding.getByName('utf-8')
).toString());
рабочая демонстрация
полный код
import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:http/http.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: HelpScreen(),
);
}
}
class HelpScreen extends StatefulWidget {
@override
HelpScreenState createState() {
return HelpScreenState();
}
}
class HelpScreenState extends State<HelpScreen> {
WebViewController _controller;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Help')),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
height: 300,
child: WebView(
initialUrl: 'abc',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller = webViewController;
_loadHtmlFromString();
},
),
),
IconButton(
icon: const Icon(
Icons.thumb_up,
semanticLabel: 'Thumbs up',
),
onPressed: () {
_loadHtmlFromString();
},
),
],
),
),
);
}
_loadHtmlFromString() async {
String fileText = '''
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
''';
_controller.loadUrl( Uri.dataFromString(
fileText,
mimeType: 'text/html',
encoding: Encoding.getByName('utf-8')
).toString());
}
}