internal_http_server 0.0.4 internal_http_server: ^0.0.4 copied to clipboard
An internal http server for flutter
Introduction #
This is a package to help you create an internal HTTP server in your app, you can let user upload the files within this web server.
Feature #
- The nice HTML layout :)
- Support drag and drop the file to upload
- Support upload multiple files
- Can CRUD and move a file and folder
- Support upload larger file (over 1GB)
- You can put the description with HTML in web server
- Support iOS and Android
Limition #
Not support to create nesting sub folders.
The demo screen capture #
How to use #
1. Init the InternalHttpServer #
InternalHttpServer server = InternalHttpServer(
title: 'Testing Web Server',
address: InternetAddress.anyIPv4,
port: 8080,
logger: const DebugLogger(),
);
2. Update your description with any HTML codes #
define the description string
final String server_description = ''' Description:
<ul>
<li>
You can put your <strong>webserver</strong> description here
</li>
<li>
It's support any <strong style='color:red'>HTML</strong>, you can describe what you want to say
</li>
</ul>
How to use:
<ul>
<li>1. You can drag and drop the file here or click the 'Upload File' button to upload</li>
<li>2. It's support larger file</li>
<li>3. You can upload multiple files once time</li>
</ul>
''';
update to web server
server.setDescription(server_description);
3. Create two method to start and stop the server #
startServer() async {
server.serve().then((value) {
setState(() {
isListening = true;
buttonLabel = 'Stop';
});
});
}
stopServer() async {
server.stop().then((value) {
setState(() {
isListening = false;
buttonLabel = 'Start';
});
});
}
create a button to start and stop server
ElevatedButton(
child: Text(buttonLabel),
onPressed: () {
if (isListening) {
stopServer();
} else {
startServer();
}
},
),
also, you need to let user know what the IP address of your web server, so you should get the device IP as below and show the IP in your APP
Future<String> getCurrentIP() async {
// Getting WIFI IP Details
String currentIP = '';
try {
for (var interface in await NetworkInterface.list()) {
for (var addr in interface.addresses) {
print(
'Name: ${interface.name} IP Address: ${addr.address} IPV4: ${InternetAddress.anyIPv4}');
if (addr.type == InternetAddressType.IPv4 &&
addr.address.startsWith('192')) {
currentIP = addr.address;
}
}
}
} catch (e) {
debugPrint(e.toString());
}
// print('currentIP========: $currentIP');
return currentIP;
}
Please find the full example here [here (../example/lib/main.dart)][here].
In the end #
Due to my limited time and energy, I warmly welcome everyone to work together to improve this project. For example, nested directories are not yet supported. :)
By the way, also welcome to my blog to let me know what do your thoughts : https://www.coderblog.in