Skip to content

Instantly share code, notes, and snippets.

View sma's full-sized avatar

Stefan Matthias Aust sma

  • I.C.N.H GmbH
  • Kiel
View GitHub Profile
@sma
sma / observable_kv.dart
Created January 26, 2024 13:36
A KV that can be observed for changes to key bindings.
/// A KV that can be observed for changes to key bindings.
class ObservableKV {
ObservableKV(this._kv);
final KV _kv;
final _listeners = <void Function(String, Object?)>[];
Stream<(Object, Object?)> observe(String prefix) {
late final StreamController<(Object, Object?)> controller;
void listener(String key, Object? value) {
@sma
sma / sqlite_kv.dart
Created January 26, 2024 13:19
A simple key-value store w/persistent sqlite3 database.
/// A simple key-value store w/persistent sqlite3 database.
class KV {
KV._(this._db);
final Database _db;
static Future<KV> open(String name) async {
return KV._(sqlite3.open(name)..execute('create table if not exists kv (k text primary key, v jsonb)'));
}
Future<Object?> get(String key) async {
@sma
sma / kv.dart
Last active January 26, 2024 13:34
A simple read-optimized in-memory key-value store w/persistent file-based redo log.
/// A simple read-optimized in-memory key-value store w/persistent file-based redo log.
class KV {
KV._(this._file, this._data);
final File _file;
final Map<String, dynamic> _data;
static Future<KV> open(File file) async {
final data = <String, dynamic>{};
if (!file.existsSync()) return KV._(file, data);
await for (final line in file //
import 'package:flutter/material.dart';
void main() {
runApp(const App());
}
class App extends StatelessWidget {
const App({super.key});
@override
import 'package:flutter/material.dart';
void main() {
runApp(const App());
}
class App extends StatelessWidget {
const App({super.key});
@override
import 'dart:async';
import 'package:flutter/material.dart';
/// See [asyncTask].
typedef Task<T> = Future<T?> Function(bool Function() cancelled);
/// Runs the future returned by [task] and shows a modal waiting dialog after
/// an initial [delay] (default 100 ms) with an optional [label] until the future
/// completes. The [task] is passed a function that returns whether the task
@sma
sma / text_cursor_overlay.dart
Created October 24, 2023 13:41
moving the overlaying the text cursor
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@sma
sma / simple_editor.md
Created September 30, 2023 09:34
An article how to create a simple object editor in Flutter

Creating such an editor can be very complicated. The principle is easy, though. Create a notifier that holds your models, observe that notifier and draw the objects accordingly to the models, then modify the model based on the UI interaction.

Here's a model:

class Box {
  Box({
    required this.center,
    required this.size,
    required this.rotation,

required this.color,

@sma
sma / fltr_web.md
Created September 20, 2023 13:50
A proof of concept for a Flutter-like framework that is a Dart web application

So you want Flutter for the web. Sure thing.

Run

dart create -t web fltr_web
cd fltr_web
dart pub get
dart pub add dev:webdev
dart run webdev serve
@sma
sma / forth.dart
Last active August 4, 2023 02:07
a tiny forth interpreter
import 'package:flutter/material.dart';
void main() {
Forth().run('V: count 5 ! : inc dup @ 1 + ! ; '
'[ [ text ] count builder [ count inc ] " Increment text button ] '
'list column app run');
}
typedef Impl = void Function(Forth f);