Skip to content

Instantly share code, notes, and snippets.

@bizz84
bizz84 / update-android-project.sh
Last active January 30, 2026 02:25
Script to update Gradle, Java and other Android project settings in a Flutter project
#!/bin/bash
# Update Gradle, Java and other Android project settings in a Flutter project
# Works with both .gradle and .gradle.kts build files
# See: https://gradle.org/releases/
# See: https://developer.android.com/build/releases/gradle-plugin#compatibility
DESIRED_GRADLE_VERSION="8.11.1"
# Build errors often show the required Java version
DESIRED_JAVA_VERSION="17"
# See: https://developer.android.com/ndk/downloads
@tolo
tolo / nested_navigation_shell_route.dart
Last active November 13, 2025 00:02
Example showing how to use go_router to build persistent nested navigation (i.e. separate nested navigation trees) with a BottomNavigationBar.
// This temporary implementation is now obsolete, see instead:
// https://pub.dev/documentation/go_router/latest/go_router/StatefulShellRoute-class.html
@ashishbeck
ashishbeck / index.js
Last active April 22, 2022 10:41
Firebase Cloud Function to keep the community scores updated for my slide puzzle project at https://github.com/ashishbeck/slide_puzzle
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const db = admin.firestore();
const FieldValue = admin.firestore.FieldValue;
exports.updateScores = functions.firestore
.document("users/{userId}")
.onUpdate((change, context) => {
const newValue = change.after.data();
@rohan20
rohan20 / main.dart
Created December 31, 2021 13:35
Flutter close iOS number keyboard (has no "Done" button)
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
import 'package:flutter/material.dart';
void main() async {
runApp(const DynamicHeader());
}
class DynamicHeader extends StatelessWidget {
const DynamicHeader({Key? key}) : super(key: key);
@override
@Nash0x7E2
Nash0x7E2 / interactive_card.dart
Last active August 31, 2022 20:08
Implementation of Flutter's Card widget using the MaterialStateProperty API for handling and responding to user interaction. This implementation allows developers to quick and easily customize properties on their card whenever a user taps and hover on the widget. Please see the following link for more information on MaterialStateProperty: https:…
/// Implementation of [Card] using the new [MaterialStateProperty] for handling
/// and reacting to user interactions.
class InteractiveCard extends StatefulWidget {
const InteractiveCard({
Key? key,
this.color,
this.shadowColor,
this.elevation,
this.shape,
this.borderOnForeground = true,
@rohan20
rohan20 / flutter_button_tap_to_shrink_effect.dart
Last active May 18, 2025 19:03
Flutter button tap to shrink animation effect
// Interactive Demo: https://dartpad.dev/b1a15c09bbb8d18c4caa9e8c41a108c0?null_safety=true
// GIF Demo: See first comment below
import 'package:flutter/material.dart';
void main() {
runApp(DemoApp());
}
class DemoApp extends StatelessWidget {
@tomalabaster
tomalabaster / wait_for_state_from_bloc.dart
Created January 3, 2021 20:32
A utility method for waiting for a bloc to yield a specific state.
import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:meta/meta.dart';
class BlocClosedWithoutYieldingStateException implements Exception {}
Future<T> waitForStateFromBloc<T>({
@required Bloc bloc,
}) {
@slightfoot
slightfoot / page_animation.dart
Last active May 16, 2020 12:16
PageView Page Animation / Transition Example - by Simon Lightfoot - 12/05/2020
// MIT License
//
// Copyright (c) 2020 Simon Lightfoot
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@gspencergoog
gspencergoog / main.dart
Created March 10, 2020 17:16
InheritedNotifier example
// Flutter code sample for
// This example shows three spinning squares that use the value of the notifier
// on an ancestor [InheritedNotifier] (`SpinModel`) to give them their
// rotation. The notifier doesn't need to know about the children, or need to
// be an animation controller, however. The `SpinModel` class could just as
// easily listen to another object (say, a separate object that keeps the
// value of a slider) that was a [Listenable], and get the value from that. The
// descendants also don't need to have an instance of the [InheritedNotifier]
// in order to use it, they just need to know that there is one in their