Neil's Custom Request
This is a simple helper for HTTP requests
With this widget, you can:
- Make get, post, put, delete request
- Make a custom request by type
- Manage multipart files
- Change headers
- Single or multiple WebSocket with restarter and error control!
- Donwload any file from https or http
Terminal preview
"GET ββ--β-β π¬ https://example.com/ β status: successful, OK
"POST β--β-β πΎ https://example.com/ β status: successful, OK
"PUT ββ--β-β π© https://example.com/ β status: successful, OK
"PATCH β-β-β π© https://example.com/ β status: successful, OK
"HEAD -β-β-β π«₯ https://example.com/ β status: successful, OK
"READ -β-β-β π https://example.com/ β status: successful, OK
"DELETE ---β ποΈ https://example.com/ β status: successful, OK
"DOWNLOAD -β ποΈ https://example.com/ β status: successful, OK
Example
await NRequest(
"http://example.com/post/",
body : { "type": 1 },
files : [ MultipartFile ]
).post((response) {
if(response.isValid) response.printStatus();
});
Methods
await NRequest("url").download((Uint8List? data) {});
await NRequest("url").get((ResponseData response) {});
await NRequest("url").post((ResponseData response) {});
await NRequest("url").put((ResponseData response) {});
await NRequest("url").patch((ResponseData response) {});
await NRequest("url").head((ResponseData response) {});
await NRequest("url").read((ResponseData response) {});
await NRequest("url").type(type: RequestType.post).then((ResponseData response) {});
Setters
url: String // Required string
headers: Map<String, String>?
token: Map<String, String>?
body: Map<String, dynamic>
formData: bool // Changue for multipart request
files: List<MultipartFile>
timeout: Duration
printUrl: bool
printHeader: bool
printBody: bool
printResponse: bool
onStart: Function()
onFinish: Function()
ResponseData Properties
url: String
type: RequestType
status: StatusData
body: dynamic
StatusData Properties
type: StatusType
code: int
isValid: bool
description: String
WebSocket
NSocketData? socketData;
NSocketController? socketController;
socketData = SocketData(
name : "Clients socket",
url : "ws url",
function : (message) => smsFunction(message)
);
// This is a setter and controller if you want to listen conection status
socketData?.addListener(()=> setState(() {}));
socketData?.hasChannelConnection : bool
socketData?.hasSocketConnection : bool
// SUPORT FOR A SINGLE OR MULTIPLE SOCKETS!
socketController = NSocketController.single(socket: socketData)
socketController = NSocketController.group( sockets: [socketData1, socketData2, ...] )
// Start listening; this includes a restarter that attempts to reconnect to the socket
// in case of disconnections or reconnections.
socketController?.listen();
// Always dispose contrllers
@override
void dispose() {
super.dispose();
socketData = null;
socketData?.dispose();
socketController = null;
socketController?.closeAll();
}