Sembast DevTools

A powerful development tool for debugging and visualizing Sembast databases in real-time. Create a web server on your mobile device to view and manage your local database from any browser on the same network.

🚀 Features

  • Real-time visualization of your Sembast database
  • Web interface accessible from any browser
  • Multiple store support - view all your stores in one place
  • CRUD operations - view, add, edit, and delete records
  • Auto-refresh - see changes in real-time
  • Network accessible - access from your computer while developing on mobile
  • Beautiful UI - clean and intuitive interface

đŸ“Ļ Installation

Add this to your pubspec.yaml:

dependencies:
  sembast_devtools: ^0.8.0

â„šī¸ Port Forwarding Notice:
When running on an Android emulator, Sembast DevTools will automatically set up ADB port forwarding for you (if adb is available in your system PATH).

If you are not using an emulator or if adb is not available, you may need to set up port forwarding manually to access the DevTools from your computer:

  1. Check existing forwards:
    adb forward --list
    
  2. If port 3338 is not listed, add it:
    adb [YOUR_EMULATOR_NAME] forward tcp:3338 tcp:3338
    
  3. Now you can access DevTools from your computer at:
    http://localhost:3338
    

Make sure adb is installed and available in your terminal.
For more details, see Android documentation.

đŸ› ī¸ Usage

Basic Setup

import 'package:sembast_devtools/sembast_devtools.dart';
import 'package:sembast/sembast_io.dart';

void main() async {
  // Your existing database setup
  final db = await databaseFactoryIo.openDatabase('my_app.db');

  // Start DevTools server
  final devtools = SembastDebugServer();
  await devtools.start(
    db,
    storeNames: {'users', 'products'}, // Optional: specify which stores to show
    port: 3338, // Optional: default is 3338
  );

  // Your app continues normally...
  runApp(MyApp());
}

Complete Example

import 'package:flutter/material.dart';
import 'package:sembast/sembast_io.dart';
import 'package:sembast_devtools/sembast_devtools.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Setup database
  final db = await databaseFactoryIo.openDatabase('example.db');

  // Add some sample data
  final usersStore = intMapStoreFactory.store('users');
  await usersStore.add(db, {'name': 'John', 'age': 30});

  // Start DevTools
  final devtools = SembastDebugServer();
  await devtools.start(db, storeNames: {'users'});

  runApp(MaterialApp(
    home: Scaffold(
      body: Center(
        child: Text('DevTools running on http://localhost:8080'),
      ),
    ),
  ));
}

🌐 Accessing the Web Interface

On the same device:

http://localhost:3338

From your computer (same network):

http://[YOUR_PHONE_IP]:3338

To find your phone's IP address:

  • Android: Settings > About Phone > Status > IP Address
  • iOS: Settings > Wi-Fi > (your network) > IP Address

đŸŽ›ī¸ API Endpoints

The server provides a REST API for programmatic access:

  • GET / - Web interface
  • GET /api/stores - List all stores
  • GET /api/stores/{storeName} - Get all records from a store
  • POST /api/stores/{storeName} - Add a new record
  • PUT /api/stores/{storeName}/{key} - Update a record
  • DELETE /api/stores/{storeName}/{key} - Delete a record

âš™ī¸ Configuration Options

await devtools.start(
  database,
  storeNames: {'store1', 'store2'}, // Only show specific stores
  port: 3338, // Custom port
);

🔒 Security Notice

âš ī¸ Important: Only use this in development!

This tool is designed for development and debugging purposes only. Do not use in production as it:

  • Exposes your database over the network
  • Has no authentication
  • Should only be used in trusted networks

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

This project is licensed under the MIT License.

🐛 Issues

Found a bug or have a feature request? Please open an issue on GitHub.

Libraries

sembast_devtools