Skip to content

Instantly share code, notes, and snippets.

View blaugold's full-sized avatar

Gabriel Terwesten blaugold

View GitHub Profile

Nutze ToStringHelper

Anstatt toString() zu überschreiben, benutze ToStringHelper:

class Person with ToStringHelper {
  Person(this.name, this.age);

  final String name;
 final int age;
extension WaitFailFast2<A, B> on (Future<A>, Future<B>) {
Future<(A, B)> get waitFailFast async {
final results = await Future.wait([$1, $2]);
return (results[0] as A, results[1] as B);
}
}
extension WaitFailFast3<A, B, C> on (Future<A>, Future<B>, Future<C>) {
Future<(A, B, C)> get waitFailFast async {
final results = await Future.wait([$1, $2, $3]);
@blaugold
blaugold / interned_bytes.dart
Last active October 19, 2023 08:57
interned_bytes.dart
import 'dart:convert';
import 'dart:typed_data';
import 'package:collection/collection.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
@immutable
class InternedBytes {
static final _internedInstances = <WeakReference<InternedBytes>>[];
flutter: INFO 14:06:50.564 + 0ms [connectivity] connection status wifi
flutter: INFO 14:06:51.262 + 698ms [sync] User is signed in: Nl7TkP9LlAgd3LrsyRtQ7voBAB52
flutter: INFO 14:06:51.340 + 77ms [analytics] couch_document_loaded (doc: game:Nl7TkP9LlAgd3LrsyRtQ7voBAB52)
flutter: INFO 14:06:51.341 + 0ms [storage] loaded document game:Nl7TkP9LlAgd3LrsyRtQ7voBAB52
flutter: INFO 14:06:51.595 + 254ms [analytics] test_segmentation (a_a: true, consent_decline: standard, ad_load_timing: standard, core_package_ui: modern, b_b: standard)
flutter: INFO 14:06:51.637 + 41ms [migration] migration 14 was already handled
flutter: INFO 14:06:51.864 + 227ms [rewards] Reward next update: null
flutter: INFO 14:06:51.982 + 117ms [core] Loading bundled puzzles...
flutter: INFO 14:06:52.151 + 168ms [daily] remaining dates (normal): [2023-10-01, 2023-10-02, 2023-10-03, 2023-10-04, 2023-10-05, 2023-10-06, 2023-10-07, 2023-10-08, 2023-10-09, 2023-10-10, 2023-10-11, 2023-10-12, 20

Installation

Packages:

  • cbl: Contains the Couchbase Lite API.
  • cbl_flutter: Initializes Couchbase Lite for Flutter.
  • cbl_dart: Initializes Couchbase Lite for Standalone Dart or Flutter unit tests.
  • cbl_flutter_ce: Selects the Community Edition for use with Flutter.
  • cbl_flutter_ee: Selects the Enterprise Edition for use with Flutter.
import 'package:fleet/fleet.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const App());
}
class App extends StatelessWidget {
const App({super.key});
import 'package:flutter/material.dart';
import 'dart:ui';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
class NoteSearchResult {
NoteSearchResult({required this.id, required this.title});
/// This method creates a NoteSearchResult from a query result.
static NoteSearchResult fromResult(Result result) => NoteSearchResult(
// The Result type has typed getters, to extract values from a result.
id: result.string('id')!,
title: result.string('title')!,
);
Future<List<NoteSearchResult>> searchNotes(Query queryString) async {
// Creating a query has some overhead and if a query is executed
// many times, it should be created once and reused. For simplicity
// we don't do that here.
final query = await Query.fromN1ql(
database,
r'''
SELECT META().id AS id, title
FROM _
WHERE type = 'note' AND match(note-fts, $query)
Future<void> createNoteFtsIndex() async {
// Existing documents will be indexed when an index is created.
await database.createIndex(
// Any existing index, with the same name, will be replaced with
// a new index, with the new configuration.
'note-fts',
FullTextIndexConfiguration(
// We want both the title and body of the note to be indexed.
['title', 'body'],
// By selecting the language, that is primarily used in the