Dart / Flutter
CloudMock does not require a custom Dart SDK. Configure the AWS SDK for Dart or your HTTP client to point at the CloudMock gateway. This works for Flutter mobile apps, Flutter web, and server-side Dart.
AWS SDK for Dart (aws_common / smithy)
Section titled “AWS SDK for Dart (aws_common / smithy)”The official AWS SDK for Dart is still in developer preview. For services that have a published Dart package, configure the endpoint:
dependencies: aws_s3_api: ^0.2.0 # if available aws_dynamodb_api: ^0.2.0 # if available aws_common: ^0.7.0Endpoint configuration
Section titled “Endpoint configuration”import 'package:aws_s3_api/s3-2006-03-01.dart';import 'package:aws_common/aws_common.dart';
final credentials = AWSCredentialsProvider(AWSCredentials( 'test', // accessKeyId 'test', // secretAccessKey));
final s3 = S3( region: 'us-east-1', credentialsProvider: credentials, endpointUrl: Uri.parse('http://localhost:4566'),);Using the http package directly
Section titled “Using the http package directly”If the official AWS Dart SDK does not cover the service you need, you can call CloudMock’s REST API directly using Dart’s http package or dio:
http package
Section titled “http package”import 'package:http/http.dart' as http;import 'dart:convert';
const cloudmockUrl = 'http://localhost:4566';
// Create an S3 bucketFuture<void> createBucket(String name) async { final response = await http.put( Uri.parse('$cloudmockUrl/$name'), headers: { 'Authorization': 'AWS4-HMAC-SHA256 ...', 'x-amz-content-sha256': 'UNSIGNED-PAYLOAD', }, ); print('Create bucket: ${response.statusCode}');}
// List S3 bucketsFuture<void> listBuckets() async { final response = await http.get( Uri.parse(cloudmockUrl), headers: { 'Authorization': 'AWS4-HMAC-SHA256 ...', }, ); print('Buckets: ${response.body}');}import 'package:dio/dio.dart';
final dio = Dio(BaseOptions( baseUrl: 'http://localhost:4566', headers: { 'Authorization': 'AWS4-HMAC-SHA256 ...', },));
// DynamoDB - CreateTableFuture<void> createTable() async { final response = await dio.post( '/', data: { 'TableName': 'Users', 'KeySchema': [ {'AttributeName': 'UserId', 'KeyType': 'HASH'} ], 'AttributeDefinitions': [ {'AttributeName': 'UserId', 'AttributeType': 'S'} ], 'BillingMode': 'PAY_PER_REQUEST', }, options: Options(headers: { 'X-Amz-Target': 'DynamoDB_20120810.CreateTable', 'Content-Type': 'application/x-amz-json-1.0', }), ); print('Table created: ${response.data}');}Community packages
Section titled “Community packages”Several community packages provide higher-level AWS clients for Dart:
aws_s3_api— S3 operations with Dart typesaws_dynamodb_api— DynamoDB operationsaws_cognito_identity_provider— Cognito User Pools
Most accept an endpointUrl parameter. Set it to http://localhost:4566 (or the appropriate host for your environment).
Flutter networking
Section titled “Flutter networking”Android emulator
Section titled “Android emulator”The Android emulator cannot reach localhost on the host machine. Use 10.0.2.2 instead:
const cloudmockUrl = 'http://10.0.2.2:4566';iOS Simulator
Section titled “iOS Simulator”The iOS Simulator shares the host Mac’s network stack. localhost works directly:
const cloudmockUrl = 'http://localhost:4566';Platform-aware endpoint
Section titled “Platform-aware endpoint”import 'dart:io' show Platform;
String get cloudmockUrl { if (Platform.isAndroid) { return 'http://10.0.2.2:4566'; } return 'http://localhost:4566';}Flutter Web
Section titled “Flutter Web”When running flutter run -d chrome, the app runs in the browser on the same machine as CloudMock. Use http://localhost:4566. CORS headers are returned by CloudMock by default.
Cleartext traffic (Android)
Section titled “Cleartext traffic (Android)”Android blocks cleartext HTTP by default. Add to android/app/src/main/AndroidManifest.xml:
<application android:usesCleartextTraffic="true" ... >Or use a more targeted network security config as described in the Kotlin guide.
App Transport Security (iOS)
Section titled “App Transport Security (iOS)”Add to ios/Runner/Info.plist:
<key>NSAppTransportSecurity</key><dict> <key>NSAllowsLocalNetworking</key> <true/></dict>Signing requests
Section titled “Signing requests”AWS APIs require Signature V4 signed requests. If you are calling CloudMock directly (without an AWS SDK), you have two options:
-
Set IAM mode to
nonein CloudMock configuration, which bypasses all authentication:iam:mode: noneThen you can make unsigned requests. This is the simplest approach for development.
-
Use an AWS SigV4 signing library for Dart. The
aws_commonpackage provides signing utilities.
When using an official AWS SDK package with endpointUrl, signing is handled automatically.
Common issues
Section titled “Common issues”AWS SDK maturity
Section titled “AWS SDK maturity”The official AWS SDK for Dart is in developer preview. Not all services have published packages. For services without a Dart SDK, use direct HTTP calls with the X-Amz-Target header for JSON-protocol services or REST-style URLs for REST-XML services.
Emulator IP addresses
Section titled “Emulator IP addresses”Use 10.0.2.2 for Android Emulator and localhost for iOS Simulator. Physical devices require the host machine’s IP on the local network.