Desplegar Drift DB con Flutter en todas las plataformas

Guía para desplegar Drift DB con Flutter en todas las plataformas soportadas (Windows, macOS, Linux, Android, iOS y Web con WASM): instalación, estructura, código y pruebas.

8 sept 2025 • 3 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Resumen rápido y compatibilidad: esta guía muestra cómo desplegar Drift DB con Flutter en todas las plataformas soportadas por Flutter incluyendo Windows, macOS, Linux, Android, iOS y WASM con fallback a JavaScript. El objetivo es ofrecer un atajo práctico para que puedas dedicar más tiempo a construir funciones y menos a resolver la configuración.

Instalar dependencias: ejecuta el siguiente comando en la raíz del proyecto para añadir las dependencias necesarias y las herramientas de desarrollo: dart pub add drift drift_flutter path_provider dev:drift_dev dev:build_runner

Estructura de archivos recomendada dentro de lib: lib/ +-- data/ +-- tables/ +-- todo_table.dart +-- database.dart +-- main.dart y en la carpeta web coloca los binarios necesarios: web/sqlite3.wasm y web/drift_worker.js

Descarga y coloca sqlite3.wasm y drift_worker.js en la carpeta web de tu build desde las fuentes oficiales del proyecto sqlite3.dart y drift. Estos archivos permiten que Drift funcione en entornos WASM y que la base de datos sea agnóstica de la plataforma.

Ejemplo simplificado de tabla en data/tables/todo_table.dart: import package:drift/drift.dart class TodoItems extends Table { IntColumn get id => integer().autoIncrement()(); TextColumn get title => text().withLength(min: 6, max: 32)(); TextColumn get content => text().named(body)(); DateTimeColumn get createdAt => dateTime().nullable()(); }

Ejemplo simplificado de base de datos en data/database.dart: import package:drift/drift.dart import package:drift_flutter/drift_flutter.dart import tables/todo_table.dart part database.g.dart @DriftDatabase(tables: [TodoItems]) class AppDatabase extends _AppDatabase { AppDatabase() : super(_connectWithDriftFlutter()); @override int get schemaVersion => 1; static QueryExecutor _connectWithDriftFlutter() { return driftDatabase(name: my_app_db, web: DriftWebOptions(sqlite3Wasm: Uri.parse(sqlite3.wasm), driftWorker: Uri.parse(drift_worker.js), ), ); } }

Nota sobre el ejemplo: gran parte del contenido de database.dart es boilerplate y suele repetirse entre proyectos. Ajusta nombres y tablas según tus necesidades reales.

Generar código: ejecuta dart run build_runner build --delete-conflicting-outputs para que Drift genere los ficheros auxiliares y el código que mapea las tablas.

Cabeceras recomendadas para servir sqlite3.wasm desde tu servidor web: Content-Type: application/wasm Cross-Origin-Opener-Policy: same-origin Cross-Origin-Embedder-Policy: require-corp Asegúrate de configurar correctamente las cabeceras según el servidor que uses para permitir el funcionamiento de WASM en navegadores.

Despliegue y pruebas locales: para probar con Flutter en modo web usa local JS con flutter run -d web-server --web-hostname 0.0.0.0 --web-port 3000 y para probar con WASM añade la opción --wasm: flutter run -d web-server --web-hostname 0.0.0.0 --web-port 3000 --wasm Ten en cuenta que para pruebas en red real es mejor usar un servidor web real con las cabeceras indicadas.

Buenas prácticas y consejos: mantén los binarios wasm y drift_worker en la carpeta web pública, revisa permisos y cabeceras CORS, y conserva la configuración de DriftWebOptions consistente entre entornos. Testea en múltiples navegadores y dispositivos para garantizar la compatibilidad.

Sobre Q2BSTUDIO: en Q2BSTUDIO somos una empresa de desarrollo de software y aplicaciones a medida especializada en soluciones modernas y seguras. Ofrecemos desarrollo de software a medida, aplicaciones a medida y servicios en inteligencia artificial, ciberseguridad y servicios cloud aws y azure. Si necesitas crear una aplicación multiplataforma robusta y escalable podemos ayudarte con experiencia en arquitecturas, despliegues y optimización de bases de datos embebidas. Conecta tus datos y dashboards con soluciones de inteligencia de negocio y Power BI para obtener valor inmediato en la toma de decisiones.

Servicios destacados de Q2BSTUDIO: desarrollo de aplicaciones personalizadas, integración de agentes IA y ia para empresas, automatización de procesos, pentesting y ciberseguridad. Si buscas una solución completa para desarrollar y desplegar una app con Drift y Flutter solicita nuestro apoyo en Desarrollo de aplicaciones multiplataforma o descubre cómo aplicamos inteligencia artificial a medida en servicios de inteligencia artificial para empresas.

Palabras clave integradas: aplicaciones a medida, software a medida, inteligencia artificial, ciberseguridad, servicios cloud aws y azure, servicios inteligencia de negocio, ia para empresas, agentes IA, power bi. Si necesitas que preparemos un repositorio ejemplo, un proyecto base o que configuremos el pipeline CI/CD para desplegar Drift en tus entornos, en Q2BSTUDIO podemos hacerlo de forma personalizada y segura.

Contacto y siguientes pasos: plantea tu caso y podemos preparar un prototipo rápido que incluya la configuración de Drift para todas las plataformas objetivo, pruebas de seguridad y la integración con servicios cloud si lo requieres.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.

Live Chat