This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<MutableDocument> createNote({ | |
required String title, | |
required String body, | |
}) async { | |
// In Couchbase Lite, data is stored in JSON like documents. The default | |
// constructor of MutableDocument creates a new document with a randomly | |
// generated id. | |
final doc = MutableDocument({ | |
// Since documents of different types are all stored in the same database, | |
// it is customary to store the type of the document in the `type` field. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For this example, we'll put the database into a global variable. | |
late final AsyncDatabase database; | |
Future<void> openDatabase() async { | |
// The database name will be used as the part of the file name | |
// of the database. | |
database = await Database.openAsync('notes-app'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
import 'package:cbl/cbl.dart'; | |
import 'package:cbl_dart/cbl_dart.dart'; | |
import 'package:flutter_test/flutter_test.dart'; | |
void main() { | |
// Each test file needs to initialize Couchbase Lite. | |
// It's a good idea to encapsulate that in a util function, | |
// that all tests use. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:cbl_flutter/cbl_flutter.dart'; | |
Future<void> main() async { | |
// If you're initializing Couchbase Lite in your `main` function | |
// make sure to initialize Flutter before Couchbase Lite. | |
WidgetsFlutterBinding.ensureInitialized(); | |
// Now initialize Couchbase Lite. | |
await CouchbaseLiteFlutter.init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies: | |
cbl: ^1.0.0 | |
cbl_flutter: ^1.0.0 | |
# This dependency selects the Community Edition of Couchbase Lite. | |
# For the Enterprise Edition add `cbl_flutter_ee` instead. | |
cbl_flutter_ce: ^1.0.0 | |
dev_dependencies: | |
# This dependency allows you to use Couchbase Lite in Flutter | |
# unit tests and not just in integration tests. | |
cbl_dart: ^1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/foundation.dart'; | |
void withAssert() { | |
assert(() { | |
runConditionalCode(); | |
return true; | |
}); | |
} | |
void withEnvironmentFlag() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
/// Overlays [overlay] over [anchor], when pushed. | |
/// | |
/// This route extends [PopupRoute], but if your implementing your own route | |
/// I suggest skimming the docs of [TransitionRoute], [ModalRoute] and | |
/// [PageRoute]. [PopupRoute] is just the most natural base class for a route | |
/// like this one. | |
class OverlayRoute<T> extends PopupRoute<T> with WidgetsBindingObserver { | |
OverlayRoute({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void withBuilder() { | |
return Builder( | |
builder: (context) { | |
return RaisedButton( | |
child: Text('Button'), | |
onPressed: () { | |
final renderObject = context.findRenderObject(); | |
} | |
); | |
} |