Skip to content

Commit a186d4d

Browse files
committed
Progress restructure api request with encryption
1 parent d00cce1 commit a186d4d

8 files changed

Lines changed: 72 additions & 72 deletions

File tree

lib/components/http_response_view.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ class HttpResponseView extends StatelessWidget {
1111
const HttpResponseView({
1212
super.key,
1313
required this.response,
14-
required this.requestBuilder,
1514
});
1615

1716
final Response? response;
18-
final HttpRequestBuilder requestBuilder;
1917

2018
String beautifyJson(Map<String, dynamic> json, {bool withSeparator = false}) {
2119
try {
@@ -43,7 +41,8 @@ class HttpResponseView extends StatelessWidget {
4341
if (isImage) {
4442
return Padding(
4543
padding: EdgeInsets.all(8),
46-
child: Image.network(requestBuilder.urlInputController?.text ?? ""),
44+
child: Image.network(
45+
HttpRequestBuilder.getInstance().urlInputController?.text ?? ""),
4746
);
4847
}
4948
if (isJson) {

lib/features/tab_bar_layout_tool_view.dart

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,48 @@ class TabBarLayoutToolView extends TabBarLayoutView {
100100
);
101101
},
102102
),
103+
IconButton(
104+
icon: Icon(MdiIcons.export),
105+
onPressed: () {
106+
var context = Navigation().tabBarDetailContext;
107+
if (context == null) return;
108+
showDialog(
109+
context: context,
110+
builder: (context) => AlertDialog(
111+
title: Text("Export"),
112+
content: TextField(
113+
decoration: InputDecoration(
114+
labelText: "Enter file name",
115+
hintText: "Enter file name",
116+
border: const OutlineInputBorder(),
117+
prefixIcon: const Icon(Icons.file_copy),
118+
),
119+
),
120+
actions: [
121+
TextButton(
122+
onPressed: () => Navigator.of(context).pop(),
123+
child: Text("Cancel")),
124+
TextButton(onPressed: () {}, child: Text("Confirm")),
125+
],
126+
),
127+
);
128+
},
129+
),
103130
],
104131
widgetBuilder: (context) => MultiProvider(
105132
providers: [
106133
ChangeNotifierProvider(
107-
create: (context) => requestBuilder,
134+
create: (context) => requestBuilder.selectedDatum,
108135
)
109136
],
110137
child: AppLayout(
111138
context: context,
112139
defaultWidget: Row(
113140
crossAxisAlignment: CrossAxisAlignment.stretch,
114-
children: [const APIViewDesktop(), ApiFileManagerView()],
141+
children: [
142+
const APIViewDesktop(),
143+
ApiFileManagerView(),
144+
],
115145
),
116146
mobileWidget: const APIViewMobile(),
117147
),

lib/features/tool/api/api_request_builder.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class HttpRestRequestDatum extends ChangeNotifier {
156156
bool isSelected = false;
157157
String method = "GET";
158158
String url = "";
159-
List<RequestData> requestData = [];
159+
List<RequestData> requestData = [RequestData()];
160160
String selectedRequest = "";
161161
String responsePath = "";
162162
Map<String, String> variables = {};
@@ -714,8 +714,6 @@ class HttpRequestBuilder extends ChangeNotifier {
714714

715715
request() => selectedDatum?.request();
716716

717-
get response => selectedDatum?.response;
718-
719717
bool get isRequesting => selectedDatum?.isRequesting ?? false;
720718

721719
HttpRequestBuilder._() {

lib/features/tool/api/api_view_desktop.dart

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ class _APIViewDesktopState extends State<APIViewDesktop> {
2727

2828
@override
2929
Widget build(BuildContext context) {
30-
final requestBuilder = context.watch<HttpRequestBuilder>();
31-
allowSubmitRequest =
32-
requestBuilder.urlInputController?.text.isNotEmpty ?? false;
30+
final selectedData = context.watch<HttpRestRequestDatum>();
31+
allowSubmitRequest = selectedData.urlInputController.text.isNotEmpty;
3332
return Expanded(
3433
child: Column(
3534
mainAxisAlignment: MainAxisAlignment.start,
@@ -41,10 +40,10 @@ class _APIViewDesktopState extends State<APIViewDesktop> {
4140
DropdownMenu(
4241
textStyle: TextStyle(
4342
fontSize: 14,
44-
color: requestBuilder.methodColor,
43+
color: selectedData.methodColor,
4544
fontWeight: FontWeight.bold,
4645
),
47-
initialSelection: requestBuilder.getRequestMethod ??
46+
initialSelection: selectedData.getRequestMethod ??
4847
HttpRequestMethodTypeExtension.defaultHttpMethod,
4948
requestFocusOnTap: false,
5049
dropdownMenuEntries: HttpRequestMethodTypeExtension
@@ -53,15 +52,15 @@ class _APIViewDesktopState extends State<APIViewDesktop> {
5352
.toList(),
5453
onSelected: (value) {
5554
if (value == null) return;
56-
requestBuilder.setRequestMethod = value;
55+
selectedData.setRequestMethod = value as String;
5756
},
5857
),
5958
const SizedBox(width: 10),
6059
SizedBox(
6160
width: 400,
6261
child: TextFormField(
6362
textInputAction: TextInputAction.done,
64-
controller: requestBuilder.urlInputController,
63+
controller: selectedData.urlInputController,
6564
decoration: InputDecoration(
6665
floatingLabelBehavior: FloatingLabelBehavior.always,
6766
border: OutlineInputBorder(),
@@ -70,16 +69,16 @@ class _APIViewDesktopState extends State<APIViewDesktop> {
7069
),
7170
onChanged: (value) => setState(() {
7271
allowSubmitRequest = value.isUrl;
73-
if (value.isEmpty) requestBuilder.reset();
72+
if (value.isEmpty) selectedData.reset();
7473
}),
7574
onFieldSubmitted: (value) =>
76-
allowSubmitRequest ? requestBuilder.request() : null,
75+
allowSubmitRequest ? selectedData.request() : null,
7776
),
7877
),
7978
const SizedBox(width: 10),
8079
TextButton(
8180
onPressed:
82-
allowSubmitRequest ? () => requestBuilder.request() : null,
81+
allowSubmitRequest ? () => selectedData.request() : null,
8382
child: const Text(
8483
"Request",
8584
style: TextStyle(fontWeight: FontWeight.bold),
@@ -95,20 +94,16 @@ class _APIViewDesktopState extends State<APIViewDesktop> {
9594
],
9695
),
9796
Expanded(
98-
child:
99-
requestBuilder.response != null && !requestBuilder.isRequesting
100-
? HttpResponseView(
101-
response: requestBuilder.response,
102-
requestBuilder: requestBuilder,
103-
)
104-
: Center(
105-
child: requestBuilder.isRequesting
106-
? const CircularProgressIndicator()
107-
: const Padding(
108-
padding: EdgeInsets.all(8.0),
109-
child: Text("Empty response"),
110-
),
111-
),
97+
child: selectedData.response != null && !(selectedData.isRequesting)
98+
? HttpResponseView(response: selectedData.response)
99+
: Center(
100+
child: selectedData.isRequesting
101+
? const CircularProgressIndicator()
102+
: const Padding(
103+
padding: EdgeInsets.all(8.0),
104+
child: Text("Empty response"),
105+
),
106+
),
112107
)
113108
],
114109
),

lib/features/tool/api/api_view_mobile.dart

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class _APIViewDesktopState extends State<APIViewMobile> {
2828

2929
@override
3030
Widget build(BuildContext context) {
31-
final requestBuilder = context.watch<HttpRequestBuilder>();
31+
final selectedData = context.watch<HttpRestRequestDatum>();
3232
return Row(
3333
crossAxisAlignment: CrossAxisAlignment.stretch,
3434
children: [
@@ -48,7 +48,7 @@ class _APIViewDesktopState extends State<APIViewMobile> {
4848
fontSize: 14,
4949
color: methodColor,
5050
fontWeight: FontWeight.bold),
51-
initialSelection: requestBuilder.getRequestMethod ??
51+
initialSelection: selectedData.getRequestMethod ??
5252
HttpRequestMethodTypeExtension.defaultHttpMethod,
5353
requestFocusOnTap: false,
5454
dropdownMenuEntries: HttpRequestMethodTypeExtension
@@ -57,7 +57,7 @@ class _APIViewDesktopState extends State<APIViewMobile> {
5757
.toList(),
5858
onSelected: (value) {
5959
if (value == null) return;
60-
requestBuilder.setRequestMethod = value;
60+
selectedData.setRequestMethod = value as String;
6161
setState(() {
6262
methodColor =
6363
HttpRequestMethodTypeExtension.methodByDisplay(
@@ -71,7 +71,7 @@ class _APIViewDesktopState extends State<APIViewMobile> {
7171
child: TextFormField(
7272
textInputAction: TextInputAction.done,
7373
style: const TextStyle(fontSize: 14),
74-
controller: requestBuilder.urlInputController,
74+
controller: selectedData.urlInputController,
7575
decoration: const InputDecoration(
7676
border: OutlineInputBorder(),
7777
hintText: "URL",
@@ -80,27 +80,24 @@ class _APIViewDesktopState extends State<APIViewMobile> {
8080
setState(() => allowSubmitRequest = value.isUrl);
8181
},
8282
onFieldSubmitted: (value) {
83-
allowSubmitRequest ? requestBuilder.request() : null;
83+
allowSubmitRequest ? selectedData.request() : null;
8484
},
8585
),
8686
),
8787
],
8888
),
8989
Expanded(
90-
child: requestBuilder.response != null &&
91-
!requestBuilder.isRequesting
92-
? HttpResponseView(
93-
response: requestBuilder.response,
94-
requestBuilder: requestBuilder,
95-
)
96-
: Center(
97-
child: requestBuilder.isRequesting
98-
? const CircularProgressIndicator()
99-
: const Padding(
100-
padding: EdgeInsets.all(8.0),
101-
child: Text("Empty response"),
102-
),
103-
),
90+
child:
91+
selectedData.response != null && !selectedData.isRequesting
92+
? HttpResponseView(response: selectedData.response)
93+
: Center(
94+
child: selectedData.isRequesting
95+
? const CircularProgressIndicator()
96+
: const Padding(
97+
padding: EdgeInsets.all(8.0),
98+
child: Text("Empty response"),
99+
),
100+
),
104101
)
105102
],
106103
),

macos/Flutter/GeneratedPluginRegistrant.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import FlutterMacOS
66
import Foundation
77

8-
import cryptography_flutter
98
import file_picker
109
import path_provider_foundation
1110
import quill_native_bridge_macos
@@ -14,7 +13,6 @@ import url_launcher_macos
1413
import video_player_avfoundation
1514

1615
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
17-
CryptographyFlutterPlugin.register(with: registry.registrar(forPlugin: "CryptographyFlutterPlugin"))
1816
FilePickerPlugin.register(with: registry.registrar(forPlugin: "FilePickerPlugin"))
1917
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
2018
QuillNativeBridgePlugin.register(with: registry.registrar(forPlugin: "QuillNativeBridgePlugin"))

pubspec.lock

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -238,22 +238,6 @@ packages:
238238
url: "https://pub.dev"
239239
source: hosted
240240
version: "3.0.6"
241-
cryptography:
242-
dependency: "direct main"
243-
description:
244-
name: cryptography
245-
sha256: d146b76d33d94548cf035233fbc2f4338c1242fa119013bead807d033fc4ae05
246-
url: "https://pub.dev"
247-
source: hosted
248-
version: "2.7.0"
249-
cryptography_flutter:
250-
dependency: "direct main"
251-
description:
252-
name: cryptography_flutter
253-
sha256: a7fc3f0de42fb0947cbf213257aa3a69c89df561d104723ede8050658621f292
254-
url: "https://pub.dev"
255-
source: hosted
256-
version: "2.3.2"
257241
csslib:
258242
dependency: transitive
259243
description:
@@ -899,7 +883,7 @@ packages:
899883
source: hosted
900884
version: "2.1.8"
901885
pointycastle:
902-
dependency: transitive
886+
dependency: "direct main"
903887
description:
904888
name: pointycastle
905889
sha256: "92aa3841d083cc4b0f4709b5c74fd6409a3e6ba833ffc7dc6a8fee096366acf5"

pubspec.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ dependencies:
4040
flutter_html: ^3.0.0-beta.2
4141
dart_jsonwebtoken: ^3.2.0
4242
file_picker: ^9.2.1
43-
cryptography: ^2.7.0
44-
cryptography_flutter: ^2.3.2
43+
pointycastle: ^4.0.0
4544

4645
dev_dependencies:
4746
flutter_test:

0 commit comments

Comments
 (0)