realm 0.2.0-alpha.2 copy "realm: ^0.2.0-alpha.2" to clipboard
realm: ^0.2.0-alpha.2 copied to clipboard

outdated

The official Realm SDK for Flutter. Realm is a mobile database - an alternative to SQLite and key-value stores.

example/lib/main.dart

////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2021 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:realm/realm.dart';

part 'main.g.dart';

@RealmModel()
class _Car {
  @PrimaryKey()
  late final String make;
}

void main() {
  print("Current PID $pid");
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    Configuration config = Configuration([Car.schema]);
    var realm = Realm(config);

    realm.write(() {
      var car = realm.add(Car("Audi"));
      print("The car is ${car.make}");
      car.make = "VW";
      print("The car is ${car.make}");
    });

    var objects = realm.all<Car>();
    var indexedCar = objects[0];
    print("The indexedCar is ${indexedCar.make}");
    
    realm.close();

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Running on: ${Platform.operatingSystem}\n'),
        ),
      ),
    );
  }
}
578
likes
0
pub points
98%
popularity

Publisher

verified publisherrealm.io

The official Realm SDK for Flutter. Realm is a mobile database - an alternative to SQLite and key-value stores.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

args, build_cli_annotations, build_runner, crypto, ffi, flutter, json_annotation, logging, meta, package_config, path, pub_semver, pubspec_parse, realm_common, realm_generator, tar

More

Packages that depend on realm