vaudb_flutter 0.1.1
vaudb_flutter: ^0.1.1 copied to clipboard
Flutter FFI plugin for the VauDB embedded Rust database engine.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:vaudb_flutter/vaudb.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _status = 'Tap "Run Sample"';
Future<void> _runSample() async {
try {
final db = VauDB();
db.open('example.vdb');
try {
db.createTable('users', ['id', 'name']);
} catch (_) {
// Ignore if already exists.
}
db.insertRow('users', ['1', 'Varish']);
final rows = db.selectAll('users');
db.close();
setState(() {
_status = 'rows=${rows.rows.length} first=${rows.rows.isNotEmpty ? rows.rows.first.values : []}';
});
} catch (e) {
setState(() {
_status = 'Error: $e';
});
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('VauDB Flutter Example')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: _runSample,
child: const Text('Run Sample'),
),
const SizedBox(height: 16),
Text(_status, textAlign: TextAlign.center),
],
),
),
),
);
}
}