Skip to content

Instantly share code, notes, and snippets.

@rodydavis
rodydavis / pocketbase_id_generator.dart
Created June 10, 2024 00:06
ID Generator from the Go codebase
import 'dart:math';
const defaultIdLength = 15;
const defaultIdAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
String pseudorandomStringWithAlphabet(int length, String alphabet) {
final List<int> b = List.filled(length, 0);
final int max = alphabet.length;
for (int i = 0; i < length; i++) {
@rodydavis
rodydavis / generator.dart
Last active May 29, 2024 21:21
Example of a possible Dart DSX (JSX like syntax) inspired by Templ in Go lang
import 'dart:io';
void main() {
final file = File('lib/hello.dsx');
final out = File('lib/hello.g.dart');
out.createSync();
out.writeAsStringSync(convert(file.readAsStringSync()));
}
String convert(String raw) {
@rodydavis
rodydavis / main.dart
Last active May 29, 2024 04:41
Gemini + Gemini
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:google_generative_ai/google_generative_ai.dart';
import 'package:url_launcher/link.dart';
final themeColor = ValueNotifier<Color>(Colors.orangeAccent);
int lastId = 0;
@rodydavis
rodydavis / main.dart
Last active May 7, 2024 18:25
Flutter AI Theme Generation (Function Calling)
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@rodydavis
rodydavis / main.dart
Last active May 7, 2024 18:25
Gemini Tasks (Function Calling)
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@rodydavis
rodydavis / dart_web_pick_file.dart
Created April 23, 2024 20:06
How to pick a file with package:web
Future<Uint8List?> pickFile() async {
final el = html.document.createElement('input') as html.HTMLInputElement;
el.type = 'file';
el.accept = 'image/*';
el.click();
final completer = Completer<Uri?>();
el.onchange = (html.Event e) {
final files = el.files;
if (files != null && files.length != 0) {
final file = files.item(0);
@rodydavis
rodydavis / main.dart
Last active May 7, 2024 18:25
Ask the Menu
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
class ChatBubble extends StatelessWidget {
const ChatBubble({
super.key,
this.child,
this.text,
required this.isUser,
});
@rodydavis
rodydavis / json_canvas.dart
Created March 22, 2024 19:34
Dart classes for JsonCanvas schema
import 'package:dart_mappable/dart_mappable.dart';
part 'schema.mapper.dart';
@MappableClass()
class JsonCanvas with JsonCanvasMappable {
List<JsonCanvasNode> nodes;
List<JsonCanvasEdge> edges;
JsonCanvas({
@rodydavis
rodydavis / main.dart
Created March 6, 2024 23:49
How to Print Multiple Objects to the Console with print()
void main() {
final number = 1;
final str = 'Hello World';
print((number, str));
print((DateTime.now(), str));
print((DateTime.now(), count: number, description: str));