sembast_devtools 0.8.1 copy "sembast_devtools: ^0.8.1" to clipboard
sembast_devtools: ^0.8.1 copied to clipboard

DevTools for Sembast database - Real-time web interface to visualize and debug your local database during development.

example/main.dart

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

import 'package:sembast_devtools/sembast_devtools.dart';

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

  // Configurar banco de dados
  final dir = await getApplicationDocumentsDirectory();
  final dbPath = join(dir.path, 'example.db');
  final db = await databaseFactoryIo.openDatabase(dbPath);

  // Inserir dados de exemplo
  await _setupSampleData(db);

  // Iniciar servidor DevTools
  final devtools = SembastDebugServer();
  await devtools.start(
    db,
    storeNames: {
      'users',
      'products',
      'settings',
    }, // Especificar quais stores mostrar
    port: 8080,
  );

  runApp(MyApp(devtools: devtools));
}

Future<void> _setupSampleData(Database db) async {
  // Store de usuários
  final usersStore = intMapStoreFactory.store('users');
  await usersStore.add(db, {
    'name': 'Alice',
    'age': 28,
    'email': 'alice@example.com',
  });
  await usersStore.add(db, {
    'name': 'Bob',
    'age': 35,
    'email': 'bob@example.com',
  });
  await usersStore.add(db, {
    'name': 'Charlie',
    'age': 22,
    'email': 'charlie@example.com',
  });

  // Store de produtos
  final productsStore = intMapStoreFactory.store('products');
  await productsStore.add(db, {
    'name': 'iPhone',
    'price': 999.99,
    'category': 'electronics',
  });
  await productsStore.add(db, {
    'name': 'MacBook',
    'price': 1299.99,
    'category': 'electronics',
  });

  // Store de configurações
  final settingsStore = intMapStoreFactory.store('settings');
  await settingsStore.add(db, {'theme': 'dark', 'notifications': true});
}

class MyApp extends StatelessWidget {
  final SembastDebugServer devtools;

  const MyApp({super.key, required this.devtools});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Sembast DevTools Example',
      theme: ThemeData(primarySwatch: Colors.blue, useMaterial3: true),
      home: HomePage(devtools: devtools),
    );
  }
}

class HomePage extends StatelessWidget {
  final SembastDebugServer devtools;

  const HomePage({super.key, required this.devtools});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Sembast DevTools Example'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              const Card(
                child: Padding(
                  padding: EdgeInsets.all(16.0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        '🚀 DevTools Server Running!',
                        style: TextStyle(
                          fontSize: 20,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      SizedBox(height: 8),
                      Text('Server is running on port 8080'),
                      SizedBox(height: 8),
                      Text(
                        'Open your computer browser and go to:',
                        style: TextStyle(fontWeight: FontWeight.w500),
                      ),
                    ],
                  ),
                ),
              ),

              // Access instructions card
              Card(
                child: Padding(
                  padding: const EdgeInsets.all(16.0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      const Text(
                        '🌐 Access URLs:',
                        style: TextStyle(
                          fontSize: 16,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      const SizedBox(height: 12),

                      // Android Emulator
                      const Text(
                        '📱 Android Emulator:',
                        style: TextStyle(fontWeight: FontWeight.w500),
                      ),
                      Container(
                        width: double.infinity,
                        margin: const EdgeInsets.symmetric(vertical: 4),
                        padding: const EdgeInsets.all(8),
                        decoration: BoxDecoration(
                          color: const Color(0xFFF5F5F5),
                          borderRadius: BorderRadius.circular(4),
                          border: Border.all(color: Colors.grey.shade300),
                        ),
                        child: const SelectableText(
                          'http://10.0.2.2:8080',
                          style: TextStyle(fontFamily: 'monospace'),
                        ),
                      ),

                      const SizedBox(height: 8),

                      // iOS Simulator
                      const Text(
                        '📱 iOS Simulator:',
                        style: TextStyle(fontWeight: FontWeight.w500),
                      ),
                      Container(
                        width: double.infinity,
                        margin: const EdgeInsets.symmetric(vertical: 4),
                        padding: const EdgeInsets.all(8),
                        decoration: BoxDecoration(
                          color: const Color(0xFFF5F5F5),
                          borderRadius: BorderRadius.circular(4),
                          border: Border.all(color: Colors.grey.shade300),
                        ),
                        child: const SelectableText(
                          'http://localhost:8080',
                          style: TextStyle(fontFamily: 'monospace'),
                        ),
                      ),

                      const SizedBox(height: 8),

                      // Real Device
                      const Text(
                        '📱 Real Device:',
                        style: TextStyle(fontWeight: FontWeight.w500),
                      ),
                      Container(
                        width: double.infinity,
                        margin: const EdgeInsets.symmetric(vertical: 4),
                        padding: const EdgeInsets.all(8),
                        decoration: BoxDecoration(
                          color: const Color(0xFFF5F5F5),
                          borderRadius: BorderRadius.circular(4),
                          border: Border.all(color: Colors.grey.shade300),
                        ),
                        child: const SelectableText(
                          'http://[YOUR_COMPUTER_IP]:8080',
                          style: TextStyle(fontFamily: 'monospace'),
                        ),
                      ),

                      const SizedBox(height: 12),
                      const Text(
                        '💡 The server runs on your device/emulator, but you access it from your computer browser!',
                        style: TextStyle(
                          fontSize: 12,
                          color: Colors.grey,
                          fontStyle: FontStyle.italic,
                        ),
                      ),
                    ],
                  ),
                ),
              ),

              const SizedBox(height: 16),

              const Card(
                child: Padding(
                  padding: EdgeInsets.all(16.0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        '📦 Available Stores:',
                        style: TextStyle(
                          fontSize: 16,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      SizedBox(height: 8),
                      Text('• users (3 records)'),
                      Text('• products (2 records)'),
                      Text('• settings (1 record)'),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
5
likes
145
points
86
downloads

Publisher

unverified uploader

Weekly Downloads

DevTools for Sembast database - Real-time web interface to visualize and debug your local database during development.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, sembast, shelf, shelf_router, shelf_static

More

Packages that depend on sembast_devtools