Skip to content

Instantly share code, notes, and snippets.

@morphingcoffee
morphingcoffee / critique.md
Last active February 21, 2022 13:23
Todo Flutter App Tech Task

Feature-blocking Bugs & Unhandled Exceptions:

  1. todos_screen.dart@62 todos list is updated within the State<TodosScreen>, but failure to call setState method does not update the UI. Could be solved by wrapping line 62 in a setState function call.
  2. The Edit Todo flow opens a selected Todo item on a new screen and "awaits" on the edited result. If the user never clicks "Submit" in the editing screen, null will be returned as the value of edited Todo and NetworkClient.updateTodo(null) will be executed (the method is not null-safe), resulting in a NoSuchMethodError exception. We should not be attempting to update Todo if the user did not perform any changes; so we should only call updateTodo and showSnackBar if the edited todo is not null.
  3. networkClient.dart@34 creating a new Todo constructs request body inline. Looks like "titles" is a typo, and may have the incorrect body structure (should consult with POST API docs). Should ideally be using a model along with its toMap function, so
@morphingcoffee
morphingcoffee / QuestSO.cs
Created January 16, 2022 19:12
C# Unity Quest ScriptableObject example class
using UnityEngine;
/**
* Avoid deserializing this class and those derived from it,
* as only Unity can instantiate Scriptable Objects - constructor call during
* deserialization is not allowed.
**/
public abstract class QuestSO: ScriptableObject
{
[SerializeField]
@morphingcoffee
morphingcoffee / SaveManager.cs
Created January 16, 2022 18:21
"CI QuickSave" package-based saving in C# Unity, using IPersistable interface
using System;
using System.Linq;
using UnityEngine;
using CI.QuickSave.Core.Storage;
/**
* Central place for triggering game saving & loading.
* Classes using [QuickSave] package will end up writing files at [Application.persistentDataPath]:
* MacOS: ~/Library/Application\ Support/DefaultCompany/<productname>/QuickSave
* Windows: %userprofile%\AppData\LocalLow\<companyname>\<productname>
@morphingcoffee
morphingcoffee / MeetQuest.cs
Created January 16, 2022 18:02
Unity C# Questing Example Snippets
using System;
using Newtonsoft.Json;
using UnityEngine;
[Serializable]
public class MeetQuest : Quest
{
[JsonProperty("meetPedestriansAmount")]
public int meetPedestriansAmount;
@morphingcoffee
morphingcoffee / activation.yml
Created January 16, 2022 17:05
Unity game build, archive and deployment to itch.io automation (Windows, Linux, MacOS)
name: Acquire activation file
on:
workflow_dispatch: {}
jobs:
activation:
name: Request manual activation file 🔑
runs-on: ubuntu-latest
steps:
# Request manual activation file
- name: Request manual activation file
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:intro_slider/dot_animation_enum.dart';
import 'package:intro_slider/list_rtl_language.dart';
import 'package:intro_slider/scrollbar_behavior_enum.dart';
import 'package:intro_slider/slide_object.dart';
@morphingcoffee
morphingcoffee / hex_color.dart
Created November 5, 2021 23:24
Dart extension for converting hex string to Color with ease
import 'dart:ui';
extension HexColor on Color {
/// String is in the format "aabbcc" or "ffaabbcc" with an optional leading "#".
static Color fromHex(String hexString) {
final buffer = StringBuffer();
if (hexString.length == 6 || hexString.length == 7) buffer.write('ff');
buffer.write(hexString.replaceFirst('#', ''));
return Color(int.parse(buffer.toString(), radix: 16));
}
@morphingcoffee
morphingcoffee / fullscreen_helper.dart
Created November 5, 2021 22:51
Flutter Web fullscreen feature helper, using 'universal_html' package.
import 'package:universal_html/js.dart' as js;
import 'package:universal_html/html.dart' as html;
void example() {
_enterFullscreen(html.document.documentElement);
_exitFullscreen(html.document);
}
/// Flutter Web: Enter Fullscreen on Firefox, Chrome, Opera, Safari, etc.
/// Based on https://stackoverflow.com/questions/29714889/how-to-request-fullscreen-in-compiled-dart