Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/rocket_client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@

# 0.0.5

* Adds `requestSimulation` method for Support api integration simulation
* Fix `Request with GET/HEAD method cannot have body` bug
42 changes: 42 additions & 0 deletions packages/rocket_client/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:developer';

import 'package:example/product_model.dart';
import 'package:example/simulation_data.dart';
import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:rocket_client/rocket_client.dart';
Expand Down Expand Up @@ -66,6 +68,12 @@ class RocketClientExampleState extends State<RocketClientExample> {
},
child: const Text('Make Request'),
),
ElevatedButton(
onPressed: () {
_makeRequestSimulation(context, "products");
},
child: const Text('Make Request Simulation'),
),
ElevatedButton(
onPressed: () {
// pass wrong endpoint for produce error
Expand All @@ -79,6 +87,40 @@ class RocketClientExampleState extends State<RocketClientExample> {
);
}

Future<void> _makeRequestSimulation(
BuildContext context, String endpoint) async {
isLoading = true;
isFailed = false;
final product = Product();
setState(() {});
// Make a GET request simulation to the /products endpoint
await client.requestSimulation(endpoint,
model: product, target: ['products'], data: productsData);
isLoading = false;
setState(() {});
// Display the model content in a dialog
if (!isFailed) {
showDialog(
// ignore: use_build_context_synchronously
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Request Simulation'),
content: Text(json.encode(product.all)),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('OK'),
),
],
);
},
);
}
}

Future<void> _makeRequest(BuildContext context, String endpoint) async {
isLoading = true;
isFailed = false;
Expand Down
Loading