sqflite_sqlcipher 1.0.0+5

  • Readme
  • Changelog
  • Example
  • Installing
  • new79

sqflite_sqlcipher #

This is a fork from the plugin sqflite.

sqflite_common version 1.0.0

This fork makes use of the Dart package sqflite_common but with a native implementation which uses the SqlCipher library on both iOS and Android. The API is the same as the sqflite plugin, only that the openDatabase method includes an optional parameter password.

The SQLCipher version of the plugin is 4.3.0 If you try to open a database encrypted with a lower version of SQLCipher, the plugin will try to migrate it to a new version using the operation PRAGMA cipher_migrate (This automatic migration to version 4 is only done in Android. PR welcome for this feature in iOS).

Install and use #

To add it in your project include this in the pubspec.yml.

  sqflite_sqlcipher: {latest version}
import 'package:sqflite_sqlcipher/sqflite.dart';

Database db = await openDatabase(
  password: "my password",
  // onCreate, onUpgrade...

Android #

REQUIRED: Flutter now enables code shrinking by default when building an APK in release mode, so you need to add the following ProGuard rules to the file android/app/proguard-rules.pro. If it does not exist, create it:

-keep class net.sqlcipher.** { *; }

If using sqflite as direct or transitive dependency #

If any of your project's dependencies uses sqflite (e.g: cached_network_image, flutter_cache_manager...), then for iOS to link correctly the SQLCipher libraries you need to override it in your pubspec.yaml file:

      url: https://www.github.com/davidmartos96/sqflite_sqlcipher.git
      path: sqflite
      ref: fmdb_override

The reason for this is that in iOS, the FMDB and FMDB/SQLCipher pods cannot be used at the same time. The override only changes that reference. The rest is the full sqflite package. If anyone knows about a better way to handle this, PRs are welcome :D

Sqflite documentation #

1.0.0+5 #

  • Initial package release, using sqflite_common as a dependency under the hood.


import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sqflite_sqlcipher/sqflite.dart';
import 'package:sqflite_sqlcipher_example/batch_test_page.dart';
import 'package:sqflite_sqlcipher_example/deprecated_test_page.dart';
import 'package:sqflite_sqlcipher_example/exception_test_page.dart';
import 'package:sqflite_sqlcipher_example/exp_test_page.dart';
import 'package:sqflite_sqlcipher_example/manual_test_page.dart';
import 'package:sqflite_sqlcipher_example/sqlcipher_test_page.dart';
import 'package:sqflite_sqlcipher_example/src/dev_utils.dart';

import 'model/main_item.dart';
import 'open_test_page.dart';
import 'raw_test_page.dart';
import 'slow_test_page.dart';
import 'src/main_item_widget.dart';
import 'todo_test_page.dart';
import 'type_test_page.dart';

void main() {

/// Sqflite test app
class MyApp extends StatefulWidget {
  // This widget is the root of your application.

  _MyAppState createState() => _MyAppState();

/// SqlCipher test page
const String testSqlCipherRoute = "/test/sqlcipher";

/// Simple test page.
const String testRawRoute = '/test/simple';

/// Open test page.
const String testOpenRoute = '/test/open';

/// Slow test page.
const String testSlowRoute = '/test/slow';

/// Type test page.
const String testTypeRoute = '/test/type';

/// Batch test page.
const String testBatchRoute = '/test/batch';

/// `todo` example test page.
const String testTodoRoute = '/test/todo';

/// Exception test page.
const String testExceptionRoute = '/test/exception';

/// Manual test page.
const String testManualRoute = '/test/manual';

/// Experiment test page.
const String testExpRoute = '/test/exp';

/// Deprecated test page.
const String testDeprecatedRoute = '/test/deprecated';

class _MyAppState extends State<MyApp> {
  var routes = <String, WidgetBuilder>{
    '/test': (BuildContext context) => MyHomePage(),
    testSqlCipherRoute: (BuildContext context) => SqlCipherTestPage(),
    testRawRoute: (BuildContext context) => RawTestPage(),
    testOpenRoute: (BuildContext context) => OpenTestPage(),
    testSlowRoute: (BuildContext context) => SlowTestPage(),
    testTodoRoute: (BuildContext context) => TodoTestPage(),
    testTypeRoute: (BuildContext context) => TypeTestPage(),
    testManualRoute: (BuildContext context) => ManualTestPage(),
    testBatchRoute: (BuildContext context) => BatchTestPage(),
    testExceptionRoute: (BuildContext context) => ExceptionTestPage(),
    testExpRoute: (BuildContext context) => ExpTestPage(),
    testDeprecatedRoute: (BuildContext context) => DeprecatedTestPage(),

  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Sqflite Demo',
        theme: ThemeData(
          // This is the theme of your application.
          // Try running your application with 'flutter run'. You'll see
          // the application has a blue toolbar. Then, without quitting
          // the app, try changing the primarySwatch below to Colors.green
          // and then invoke 'hot reload' (press 'r' in the console where
          // you ran 'flutter run', or press Run > Hot Reload App in IntelliJ).
          // Notice that the counter didn't reset back to zero -- the application
          // is not restarted.
          primarySwatch: Colors.blue,
        home: MyHomePage(title: 'Sqflite Demo Home Page'),
        routes: routes);

/// App home menu page.
class MyHomePage extends StatefulWidget {
  /// App home menu page.
  MyHomePage({Key key, this.title}) : super(key: key) {
        "Sqlcipher tests", "Simple tests with an encrypted database",
        route: testSqlCipherRoute));
        MainItem("Raw tests", "Raw SQLite operations", route: testRawRoute));
    _items.add(MainItem("Open tests", "Open onCreate/onUpgrade/onDowngrade",
        route: testOpenRoute));
        .add(MainItem('Type tests', 'Test value types', route: testTypeRoute));
    _items.add(MainItem('Batch tests', 'Test batch operations',
        route: testBatchRoute));
        MainItem('Slow tests', 'Lengthy operations', route: testSlowRoute));
        'Todo database example', 'Simple Todo-like database usage example',
        route: testTodoRoute));
    _items.add(MainItem('Exp tests', 'Experimental and various tests',
        route: testExpRoute));
    _items.add(MainItem('Exception tests', 'Tests that trigger exceptions',
        route: testExceptionRoute));
    _items.add(MainItem('Manual tests', 'Tests that requires manual execution',
        route: testManualRoute));
    _items.add(MainItem('Deprecated test',
        'Keeping some old tests for deprecated functionalities',
        route: testDeprecatedRoute));

    // Uncomment to view all logs

  final List<MainItem> _items = [];

  /// Page title.
  final String title;

  _MyHomePageState createState() => _MyHomePageState();

String _debugAutoStartRouteName;

/// (debug) set the route to start with.
String get debugAutoStartRouteName => _debugAutoStartRouteName;

/// Deprecated to avoid calls
set debugAutoStartRouteName(String routeName) =>
    _debugAutoStartRouteName = routeName;

class _MyHomePageState extends State<MyHomePage> {
  String _platformVersion = 'Unknown';

  int get _itemCount => widget._items.length;

  void initState() {

  // Platform messages are asynchronous, so we initialize in an async method.
  Future initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      // ignore: deprecated_member_use
      platformVersion = await Sqflite.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version';

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;

    print('running on: ' + _platformVersion);

    // Use it to auto start a test page
    if (debugAutoStartRouteName != null) {
      // only once

      // await Navigator.of(context).pushNamed(testExpRoute);
      // await Navigator.of(context).pushNamed(testRawRoute);
      var future = Navigator.of(context).pushNamed(debugAutoStartRouteName);
      // ignore: deprecated_member_use_from_same_package
      debugAutoStartRouteName = null;
      await future;
      // await Navigator.of(context).pushNamed(testExceptionRoute);

  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
              Center(child: Text('Sqflite demo', textAlign: TextAlign.center)),
            ListView.builder(itemBuilder: _itemBuilder, itemCount: _itemCount));

  //new Center(child: new Text('Running on: $_platformVersion\n')),

  Widget _itemBuilder(BuildContext context, int index) {
    return MainItemWidget(widget._items[index], (MainItem item) {

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  sqflite_sqlcipher: ^1.0.0+5

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:sqflite_sqlcipher/sqflite.dart';
import 'package:sqflite_sqlcipher/sql.dart';
import 'package:sqflite_sqlcipher/sqlite_api.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Mar 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
flutter 0.0.0
path >=1.5.1 <3.0.0 1.6.4
sqflite_common ^1.0.0 1.0.0+1
synchronized >=2.0.2 <4.0.0 2.2.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
http >=0.12.0+2
pedantic >=1.4.0 <3.0.0
process_run >=0.10.7
test_api any