shelf_flutter_asset

Last updated:

0 purchases

shelf_flutter_asset Image
shelf_flutter_asset Images
Add to Cart

Description:

shelf flutter asset

shelf_flutter_asset #




A simple handler for the Shelf ecosystem to serve files from Flutter assets.
Usage #
Bind as root handler:
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_flutter_asset/shelf_flutter_asset.dart';

void main() {
var assetHandler = createAssetHandler(defaultDocument: 'index.html');

io.serve(assetHandler, 'localhost', 8080);
}
copied to clipboard
Bind with shelf_router:
import 'package:shelf_router/shelf_router.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;

void main() {
var app = Router();
final assetHandler = createAssetHandler();

app.get('/hello', (Request request) {
return Response.ok('hello-world');
});

app.get('/assets/<ignored|.*>', (Request request) {
return assetHandler(request.change(path: 'assets'));
});

io.serve(app, 'localhost', 8080);
}
copied to clipboard
Bind with shelf_router and custom root path:
import 'package:shelf_router/shelf_router.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;

void main() {
var app = Router();
final assetHandler = createAssetHandler(rootPath: 'assets/html');

app.get('/hello', (Request request) {
return Response.ok('hello-world');
});

app.get('/assets/<ignored|.*>', (Request request) {
return assetHandler(request.change(path: 'assets/html'));
});

io.serve(app, 'localhost', 8080);
}
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.