shelf_swap

Last updated:

0 purchases

shelf_swap Image
shelf_swap Images
Add to Cart

Description:

shelf swap

shelf_swap #
Server-driven UI for Flutter.
This package provides a swap handler for shelf based servers.

Swap is still an experimental project.
Use it at your own risks!

Example #
import 'package:server/src/widgets/user.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf_router/shelf_router.dart';
import 'package:shelf_swap/shelf_swap.dart';

import 'widgets/hello.dart';

void main() {
var app = Router();

app.get('/hello', widget((context) async {
return const HelloWorld();
}));

app.get('/user/<userId>', (Request request, String userId) {
return widget((context) async {
return User(userId: userId);
})(request);
});

final pipeline = const Pipeline().addMiddleware(logRequests()).addHandler(app);

final server = await shelf_io.serve(
pipeline,
'localhost',
8080,
);

// Enable content compression
server.autoCompress = true;

print('Serving at http://${server.address.host}:${server.port}');
}

class HelloWorld extends StatelessWidget {
const HelloWorld({
super.key,
});

@override
Widget build(BuildContext context) {
return Text('Hello!');
}
}

class User extends StatelessWidget {
const User({
super.key,
required this.userId,
});

final String userId;

@override
Widget build(BuildContext context) {
return Text('Hello ${userId}!');
}
}
copied to clipboard
See also #

swap
flutter_swap

Thanks #

HTMX for its swapping concept based on requests

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.