Skip to content

Instantly share code, notes, and snippets.

@creativecreatorormaybenot
creativecreatorormaybenot / main.dart
Last active October 11, 2022 04:39
flutter_riverpod go_router sample setup
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
// For context: https://github.com/flutter/flutter/issues/112915.
// This is crucial for making sure that the same navigator is used
// when rebuilding the GoRouter and not throwing away the whole widget tree.
final _navigatorKey = GlobalKey<NavigatorState>();
// We need to make sure we have access to the location of the previous router
import 'dart:math';
import 'dart:ui';
void main() {
final path = Path();
path.moveTo(0, 200);
path.lineTo(10, 210);
path.lineTo(30, 190);
path.lineTo(55, 150);
path.lineTo(80, 205);
@creativecreatorormaybenot
creativecreatorormaybenot / main.dart
Last active November 12, 2021 10:36
Firestore in Dartpad
// https://twitter.com/creativemaybeno/status/1458523044557770755?s=20
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
Future<void> main() async {
await Firebase.initializeApp(
options: const FirebaseOptions(
apiKey: 'AIzaSyCEfiLLknrsFhk6VCUdKKvOjrWEaJp61uQ',
@creativecreatorormaybenot
creativecreatorormaybenot / OpacityHex.markdown
Last active September 3, 2024 05:53 — forked from passiondroid/OpacityHex.markdown
Opacity Percentage to Flutter Opacity Hex Color code

Flutter uses hexadecimal ARGB values for colors, which are formatted as const Color(0xAARRGGBB). That first pair of letters, the AA, represent the alpha channel. You must convert your decimal opacity values to a hexadecimal value. Here are the steps:

Alpha Hex Value Process

  • Take your opacity as a decimal value and multiply it by 255. So, if you have a block that is 50% opaque the decimal value would be .5. For example: .5 x 255 = 127.5

  • The fraction won't convert to hexadecimal, so you must round your number up or down to the nearest whole number. For example: 127.5 rounds up to 128; 55.25 rounds down to 55.

  • Enter your decimal value in a decimal-to-hexadecimal converter, like http://www.binaryhexconverter.com/decimal-to-hex-converter, and convert your values.

@creativecreatorormaybenot
creativecreatorormaybenot / index.html
Created April 10, 2021 20:42
Flutter web keyboard & mouse utilities
// https://editor.rive.app
<body>
<script>
document.body.addEventListener("contextmenu", function (event) {
event.preventDefault();
});
</script>
<!-- Handle keyboard input events -->
<script>
@creativecreatorormaybenot
creativecreatorormaybenot / tap_recorder.dart
Last active August 4, 2021 21:24
Flutter tap recorder widget
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/widgets.dart';
/// This is code that I (https://twitter.com/creativemaybeno) wrote for a
/// StackOverflow answer.
/// You can find it here: https://stackoverflow.com/a/65067655/6509751.
@creativecreatorormaybenot
creativecreatorormaybenot / main.dart
Created November 2, 2020 09:55
Bouncing Flutter logo deluxe
import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
// https://twitter.com/creativemaybeno/status/1323082856898404352?s=20
void main() {
runApp(MaterialApp(
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
@creativecreatorormaybenot
creativecreatorormaybenot / main.dart
Created July 24, 2020 12:54
late in constructors
void main() {
// Construct the object first.
final baz = Baz(calculate('assignmentInConstructor'));
// Call access to access the late variables and initialize them if they are lazy.
baz.access();
}
class Baz {
Baz(
void main() {
Future(() => print('future 1'));
Future(() => print('future 2'));
// Microtasks will be executed before futures.
Future.microtask(() => print('microtask 1'));
Future.microtask(() => print('microtask 2'));
}