-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
147 lines (130 loc) · 3.43 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Developed by Eng. Mouaz M. Al-Shahmeh
import 'package:api_guide/api_guide.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
// Create the main application widget
return const MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter API Guide Example',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
// Use APIGuide package with display method and pass needed parameters.
return APIGuide().display(
context: context,
// Pass the API version as a double number.
version: 1.0,
// Pass the API last update as a DateTime.
latestUpdate: DateTime.parse('2023-10-10'),
// Pass the API introduction as a String.
apiIntro: 'This is some introduction to API Guide.',
// Pass the API Items List with all needed properties.
apiItems: _apiItems,
// Pass the API Servers as needed.
servers: [
const APIServer(
urlHost: 'https://example.com',
),
],
// Pass the API FAQs items as needed
apiFaqs: [
APIGuideFAQ(
question: 'Can Dash Fly?',
answer: 'Yes, Dash can Fly.',
),
],
);
}
}
// Define API Items with all needed properties
List<APIItem> _apiItems = [
// Define the first API item
APIItem(
title: 'All Dashes',
urlPath: '/dashes',
description: 'All Dashes get example description.',
securitySchemes: [],
// Define the request for the first API item
request: APIGuideRequest(
method: HttpRequestMethod.GET,
params: [],
body: [],
),
// Define the response for the first API item
response: [
const APIGuideResponse(
statusCode: HttpResponseStatusCode.OK,
headers: [],
body: {
"status": 200,
"data": {
"name": "Dash",
"isFly": true,
}
},
),
],
),
// Define the second API item
APIItem(
title: 'Create',
urlPath: '/create',
description: 'Store Dash post example description.',
securitySchemes: [],
// Define the request for the second API item
request: APIGuideRequest(
method: HttpRequestMethod.POST,
params: [],
body: [
const APIGuideRequestBody(
key: 'name',
value: 'Dash',
type: PropertyType.string,
description: 'This is the name attribute.',
isRequired: true,
),
const APIGuideRequestBody(
key: 'isFly',
value: true,
type: PropertyType.boolean,
description: 'This is the isFly attribute.',
isRequired: true,
),
],
),
// Define the response for the second API item
response: [
const APIGuideResponse(
statusCode: HttpResponseStatusCode.OK,
headers: [],
body: {
"status": 200,
"data": {
"message": "Data Stored Successfully.",
}
},
),
const APIGuideResponse(
statusCode: HttpResponseStatusCode.BadRequest,
headers: [],
body: {
"status": 400,
"data": {
"message": "Error Data Not Stored!",
}
},
),
],
),
];