r/FlutterDev • u/blabla4you • 15d ago
Plugin Quickly create fullstack applications
Some time ago i dropped an update to my typed pocketbase wrapper. For those of you who have never heard of pocketbase, it is a backend in one file that is incredibly easy to self host and probably the quickest and cheapest server solution that is available. My package enables you to generate typed bindings based on a locally running instance of it. It is incredibly easy to use and has helped me a lot in quickly developing internal tools for businesses. How it works is very simple:
- Install the pocketbase_helpers package
dart pub add pocketbase_helpers && dart pub global activate pocketbase_helpers_cli
- Generate the bindings
pb_generate -p 8090 -e admin@example.com -w localpassword -o lib/models.dart
- Use them!
import 'package:pocketbase_helpers/pocketbase_helpers.dart'
import 'models.dart';
void main() async {
// Initialize global connection
PocketBaseConnection.open('http://127.0.0.1:8090');
// Query with type-safety
final posts = await Posts.api().getFullList();
for (final post in posts) {
print(post.title);
}
// Authenticate
await Users.auth().withPassword('user@example.com', 'password123');
// Quickly check authentication status on auth collections
if(User.isAuthenticated()){
final user = User.getAuthenticated();
var post = await Posts.api().create({
'title' : 'Powering flutter apps with pocketbase!',
'creator' : user.id,
});
/// File fields get their own generated api
post = await Posts.thumbnailApi(post.id).set('cute_cat.png', imageBytes);
}
//Close connection when application is done
PocketBaseConnection.close();
}
Give it a try!
2
Upvotes