Skip to content

Instantly share code, notes, and snippets.

import 'package:json_annotation/json_annotation.dart';
part 'gpt_choice_message.g.dart';
@JsonSerializable(explicitToJson: true)
class GptChoiceMessage{
String role;
String content;
import 'gpt_choice_message.dart';
import 'package:json_annotation/json_annotation.dart';
part 'gpt_choice.g.dart';
@JsonSerializable(explicitToJson: true)
class GptChoice {
GptChoiceMessage message;
@JsonKey(name: 'finish_reason')
import 'gpt_choice.dart';
import 'gpt_usage.dart';
import 'package:json_annotation/json_annotation.dart';
part 'gpt_message.g.dart';
@JsonSerializable(explicitToJson: true)
class GptMessage {
String id;
@jtmuller5
jtmuller5 / main.dart
Created December 5, 2022 03:46
silent-marsh-8079
import 'dart:math';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
@jtmuller5
jtmuller5 / increment_version.dart
Last active December 3, 2022 00:24
Dart function to increment the version and build numbers of flutter apps. Built by Joe Muller and chat GPT.
import 'dart:developer';
import 'dart:io';
import 'package:yaml/yaml.dart';
import 'package:yaml_writer/yaml_writer.dart';
/// Run by calling dart increment_version.dart major/minor/patch
void main(List<String> args) {
// Use the provided argument to determine the version type to increment,
// or default to minor if no argument is provided
@jtmuller5
jtmuller5 / in_list_converter.dart
Created July 16, 2022 21:55
Json converter for lists of integers
import 'dart:convert';
import 'package:json_annotation/json_annotation.dart';
class IntListConverter implements JsonConverter<List<int>?, String> {
const IntListConverter();
@override
List<int>? fromJson(String? json) => List<int>.from(jsonDecode(json ?? '[]').map((e) => e.toInt()));
bool confirm = await showDialog<bool>(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Are you sure?'),
content: const Text('This action cannot be undone.'),
actions: [
TextButton(
child: const Text('Cancel'),
onPressed: (){
/// Get the color from a gradient at a specific position
/// Position should be between 0 and 1
extension ColorGetter on Gradient {
Color? colorAtPosition({
required double position,
}) {
List<double> _stops = stops ?? List.generate(colors.length, (index) => index * (1 / (colors.length-1)));
for (var stop = 0; stop < _stops.length - 1; stop++) {
class FirstTimeView extends HookWidget {
@override
Widget build(BuildContext context) {
TickerProvider tickerProvider = useSingleTickerProvider();
return ViewModelBuilder<FirstTimeViewModel>.reactive(
viewModelBuilder: () => FirstTimeViewModel(tickerProvider),
builder: (context, model, child) {
return Scaffold(
appBar: AppBar(
/// Get the color from a gradient at a specific position
Color? colorAlongGradient({
required List<Color> colors,
List<double>? stops,
required double position,
}) {
stops ??= List.generate(colors.length, (index) => index * (1 / (colors.length-1)));
for (var s = 0; s < stops.length - 1; s++) {
final leftStop = stops[s], rightStop = stops[s + 1];