Skip to content

Instantly share code, notes, and snippets.

@osaxma
osaxma / flutter_backdrop_ex.dart
Created December 22, 2019 17:32
Flutter Backdrop Example for DartPad
// taken from: https://github.com/iampawan/FlutterBackdrop
// copy paste to https://dartpad.dev/ and should work
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.teal),
home: BackdropPage(),
@osaxma
osaxma / SO_56071731.dart
Last active November 14, 2020 11:18
Expand Shrink Cards with Scrolling in ListView
// answer for:
// https://stackoverflow.com/questions/64826393/how-can-i-implement-this-specific-scroll-animation-using-flutter/
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
@osaxma
osaxma / hasura_postgres_docker_notes.md
Last active December 4, 2021 20:59
Notes on working with Hasura, Postgres and Docker in local development
@osaxma
osaxma / datetime_bug.dart
Last active February 6, 2021 09:46
lost microseconds with DateTime.parse or DateTime.fromMicrosecondsSinceEpoch
// Based on Flutter 1.26.0-17.3.pre Dart SDK 2.10.4
// filed issue at https://github.com/dart-lang/sdk/issues/44876
main() {
final datetimeParsed = DateTime.parse('2021-02-05T22:37:12.933232+00:00');
final datetimeMS = DateTime.fromMicrosecondsSinceEpoch(1612564632933232);
print(datetimeParsed.toIso8601String()); // prints 2021-02-05T22:37:12.933Z
print(datetimeMS.toUtc().toIso8601String()); // prints 2021-02-05T22:37:12.933Z
print(datetimeParsed.microsecondsSinceEpoch); // prints 1612564632933000
@osaxma
osaxma / hasura_connect_ex.dart
Last active March 4, 2024 09:38
a workaround for keeping haura_connect subscriptions alive when using JWT
import 'dart:async';
import 'package:meta/meta.dart';
import 'package:hasura_connect/hasura_connect.dart';
import 'package:http/http.dart' as http;
// problem:
// when subscribing to`HasuraConnect.subscription`, a websocket connection is created on the first subscription
// call. The websocket connection is created only once with the initial subscription and the provided TokenInterceptor
// or headers. When the token expires during an active subscription, HasuraConnect doesn't stop the subscription, or try
// to reconnect with the latest token in in the TokenInterceptor nor does it throw an error. It'll keep calling `onRequest`
@osaxma
osaxma / svg_pattern_example.dart
Last active February 20, 2021 09:31
An example of using an svg pattern as a background with the help of Flutter Shape Maker
// so it doesn't conflict with Image from material package
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
// svg from hero patterns (I Like Food): https://www.heropatterns.com/
// converted to CustomPainter code using: https://fluttershapemaker.com/
void main() {
runApp(SvgPatternExample());
@osaxma
osaxma / quadraticCurvePoint.dart
Last active April 6, 2021 13:48
Find the coordinates of a point along a quadratic Bezier curve in dart.
// credit: https://stackoverflow.com/a/9195706/10976714
// The formulas to calculate the coordinates of a point at any given position (from 0 to 1) on the Bezier curve are:
// x(t) = (1-t)^2 * x1 + 2 * (1-t) * t * x2 + t^2 * x3
// y(t) = (1-t)^2 * y1 + 2 * (1-t) * t * y2 + t^2 * y3
// where (x1, y1) is the starting point, (x2, y2) is the control point and (x3, y3) is the end point.
// get a point along the Bezier curve line
// If you pass the start, end & control points, along with 0.5 for the halfway position, you get the offset to that point
Offset getQuadraticCurvePoint(Offset start, Offset control, Offset end, double position) {
@osaxma
osaxma / stream_provider_example.dart
Last active January 9, 2022 14:04
an example for stream provider
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
import 'dart:math';
import 'package:flutter/material.dart';
void main() {
runApp(const WindowApp());
}
class WindowApp extends StatelessWidget {
const WindowApp({Key? key}) : super(key: key);