Skip to main content

Flutter Tutorial: Flutter Database for Dart-native Objects with Objectsbox



ObjectsBox is a super-fast Flutter database for storing and syncing Dart objects.
  • High performance - improving response rates and enabling real-time applications.
  • ACID compliant - Atomic, Consistent, Isolated, Durable.
  • Multiplatform - Android, iOS, macOS, Linux, Windows.
  • Scalable - grows with your app, handling millions of objects with ease.
  • Relations - object links / relationships are built-in.
  • Queries - filter data as needed, even across relations.
  • Statically typed - compile time checks & optimizations.
  • Schema migration - change your model with confidence.
  • Data Sync - keeps data in sync offline or online, between devices and servers.
ObjectsBox example code:


@Entity()
class Person {
  int id;

  String firstName;
  String lastName;

  Person({this.id = 0, required this.firstName, required this.lastName});
}

final store = await openStore(); 
final box = store.box();

var person = Person(firstName: 'Joe', lastName: 'Green');

final id = box.put(person);  // Create

person = box.get(id)!;       // Read

person.lastName = "Black";
box.put(person);             // Update

box.remove(person.id);       // Delete

// find all people whose name start with letter 'J'
final query = box.query(Person_.firstName.startsWith('J')).build();
final people = query.find();  // find() returns List

Example

Add these dependencies to your pubspec.yaml:

dependencies:
  objectbox: ^1.4.1
  objectbox_flutter_libs: any
  # for ObjectBox Sync use this dependency instead:
  # objectbox_sync_flutter_libs: any

dev_dependencies:
  build_runner: ^2.0.0
  objectbox_generator: any
  • Install the packages: flutter pub get

  • For iOS: in the Flutter Runner Xcode project

    • increase the deployment target to at least iOS 11 and,
    • under Architectures, replace ${ARCHS_STANDARD} with arm64 (or $ARCHS_STANDARD_64_BIT). See FAQ for details.
  • For sandboxed macOS apps: specify an application group. Check all macos/Runner/*.entitlementsfiles if they contain a <dict> section with correct group ID info. Change the string value to the DEVELOPMENT_TEAM found in Xcode settings, plus an application-specific suffix, for example:

    <key>com.apple.security.application-groups</key>
    <array>
      <string>FGDTDLOBXDJ.demo</string>
    </array>
    

    Next, in the app code, pass the same string when opening the Store, for example: openStore(macosApplicationGroup: 'FGDTDLOBXDJ.demo').
    Note: Pick a short group identifier; there's an internal limit in macOS that requires the complete string to be 19 characters or fewer.

  • For Sync + Android: in android/app/build.gradle set minSdkVersion 21 in section android -> defaultConfig.

  • In order to run Flutter unit tests locally on your machine, install the native ObjectBox library on your host machine (same as you would if you developed for Dart native, as described in the next section):

    bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-dart/main/install.sh)
    

Done!

Comments

Popular posts from this blog

Cara Disable Antimalware Service Executable di Windows 10

Disadari atau tidak, Windows 10 (dan juga windows-windows lainnya) hadir dengan banyak sekali aplikasi bloatware (aplikasi yang tidak perlu-perlu amat dimiliki oleh end user). Contohnya, adalah aplikasi yang seharusnya sudah tergantikan fungsinya oleh antivirus, seperti Antimalware Service Executable . Aplikasi ini dicurigai membuat Windows 10 mengalami inefisiensi memori/RAM, memakan resource yang tinggi, dengan Load yang tinggi (tanpa limit terkadang). Nah, berikut adalah cara men-disable nya: Tekan tombol Windows + I untuk membuka apliaksi Windows Setting. Pilih icon menu Update and Security Pilih lagi menu disamping kiri Windows Security Pada jendela baru yang muncul, ada pilihan Virus & Threat protection Klik ini Lalu matikan proses Real-time protection tersebut. Dengan Regedit. Buka dialog regedit, Windows + R dan ketik ‘regedit’ Cari Folder regedit ini HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender Buat sebuah DWORD baru dengan klik kanan

Setup Debian 11 Official Repository In sources.list (/etc/apt/sources.list)

When you install Debian 11 using a DVD, the OS installer sets the DVD as the source for getting packages for your system if you didn't choose to scan for network mirrors. Due to this reason, the system would ask you to insert a DVD if the disc is not present in the DVD drive when you try to install any software.  Also, the packages on DVD may not be the latest release.  So, we need to get the packages from the Internet. Media change: please insert the disc labeled 'Debian GNU/Linux 11.0.0 _Bullseye_ - Official amd64 DVD Binary-1 20210814-10:04' in the drive '/media/cdrom/' and press [Enter] The /etc/apt/sources.list file with DVD as a source would look something like below. # deb cdrom:[Debian GNU/Linux 11.0.0 _Bullseye_ - Official amd64 DVD Binary-1 20210814-10:04]/ bullseye contrib main deb cdrom:[Debian GNU/Linux 11.0.0 _Bullseye_ - Official amd64 DVD Binary-1 20210814-10:04]/ bullseye contrib main deb http://security.debian.org/debian-security bullseye-security

Cara Membuat Live USB VMWare ESXi 6.7 di Linux (Debian/CentOS)

VMWare ESXi 6.7 menyediakan satu installer dalam format CDROM ISO. Dalam tutorial kali ini kita akan membuat sebuah live USB dengan menggunakan sistem Linux, misalnya Debian dan CentOS. Untuk keperluan tutorial kali ini silakan pastikan sudah ada download installer ISO ESXi 6.7 dari https://my.vmware.com Siapkan satu USB Flashdisk dengan kapasitas lebih dari 1GB. Format dalam satu partisi dengan tool yang biasa dipakai dalam format partisi FAT32. Misal dengan FDISK: [sourcecode] fdisk /dev/sdX [/sourcecode] format ke FAT32: [sourcecode]mkfs.fvat -F 32 -n USB /dev/sdX1[/sourcecode] selanjutnya, kita buat USB tersebut bootable dengan syslinux. Bagi linuxnya belum ada syslinux, silakan install dulu (apt-get install syslinux atau yum install syslinux).