shelf_flutter_asset 0.0.4 shelf_flutter_asset: ^0.0.4 copied to clipboard
A simple handler for the Shelf ecosystem to serve files from Flutter assets.
import 'package:flutter/material.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_flutter_asset/shelf_flutter_asset.dart';
import 'package:webview_flutter/webview_flutter.dart';
void main() {
final assetHandler = createAssetHandler(defaultDocument: 'index.html');
io.serve(assetHandler, 'localhost', 8080);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Shelf Flutter Asset Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Shelf Flutter Asset Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late final WebViewController _controller;
@override
void initState() {
super.initState();
_controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setBackgroundColor(const Color(0x00000000))
..loadRequest(Uri.parse('http://localhost:8080'));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: WebViewWidget(controller: _controller),
);
}
}