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 / 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
Last active October 3, 2024 14:55
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 web # because template uses outdated version
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);
@sma
sma / py.dart
Last active June 11, 2023 09:21
/// A Python runtime written in Dart.
///
/// Create [Python] instance to set and lookup variables, create classses
/// and instances and call functions or methods. It is highly incomplete.
///
/// It uses Dart types for Python types, that is `null` for `None`, `int`
/// for `int` and `double` for `float`, `String` for `str`, `PyList` for
/// `list` and `PyDictionary` for `dict`. Python classes are represented
/// by [PyClass] and instances by [PyInstance]. A function is represented
/// by [PyFunction]. A method is represented by [PyMethod] which combines
import 'dart:convert';
/// Provides translations from keys to either strings or plural forms.
///
/// Use `format('Hello %s', ['world'])` to format a string with arguments.
/// You can use `%s` for strings, `%d` for integers, and `%f` for doubles.
/// To escape a percent sign, use `%%`. You can also use `%p(key)` to
/// insert a plural form based on an intger argument.
///
/// Use `string('key')` or `string('key', ['arg'])` to the translation for
@sma
sma / presentation.dart
Created May 24, 2023 08:37
A proof of concept of a keynote-like presentation in Flutter
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
abstract class Slide extends StatelessWidget {
const Slide({super.key, this.title});
final String? title;
@override
Widget build(BuildContext context) {
import 'package:flutter/material.dart';
class ShieldBadge extends StatelessWidget {
const ShieldBadge({
super.key,
required this.leftLabel,
required this.rightLabel,
this.leftColor = Colors.black87,
this.rightColor = Colors.deepOrange,
this.textColor = Colors.white,

I want to support indentation in a multiline TextField.

What's the best way to do so? Here's my current approach.

To indent on TAB, I use an explicit TextEditingController and wrap the TextField in a CallbackShortcuts widget to detect the TAB key. I know I could use intents and actions here, but it's simpler this way. I can access then controller from the callbacks.

class _Editor extends State<Editor> {
  final _controller = TextEditingController();

I wrote

/// Parses [input] as an .ini configuration.
Map<String, Map<String, String>> 

and Copilot completed this:

/// Parses [input] as an .ini configuration.
Map<String, Map<String, String>> parse(String input) {

final result = >{};