Skip to content

Instantly share code, notes, and snippets.

View blaugold's full-sized avatar

Gabriel Terwesten blaugold

View GitHub Profile
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.
// 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');
}
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.
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();
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
@blaugold
blaugold / main.dart
Created September 15, 2021 14:38
Flutter-Display-DevicePixelRatio
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
import 'package:flutter/foundation.dart';
void withAssert() {
assert(() {
runConditionalCode();
return true;
});
}
void withEnvironmentFlag() {
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({
Matrix4 getAnchorToNavigatorTransform(RenderObject anchor, RenderObject navigator) {
// These two transforms project points from the local coordinate spaces of their
// respective RenderObjects to the global coordinates space.
Matrix4 anchorTransform = anchor.getTransformTo(null);
Matrix4 navigatorTransform = navigator.getTransformTo(null);
// This transform projects points from the local coordinates space of [anchor]
// to the global coordinate space and from there to the local coordinate space
// of [navigator] in one step.
return anchorTransform..multiply(Matrix4.tryInvert(navigatorTransform));
}
void withBuilder() {
return Builder(
builder: (context) {
return RaisedButton(
child: Text('Button'),
onPressed: () {
final renderObject = context.findRenderObject();
}
);
}