Skip to content

Instantly share code, notes, and snippets.

View rohan20's full-sized avatar

Rohan Taneja rohan20

View GitHub Profile
@rohan20
rohan20 / flutter_button_tap_to_shrink_effect.dart
Last active February 24, 2024 00:20
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 {
@rohan20
rohan20 / main.dart
Created January 7, 2022 16:43
Flutter Marquee text or normal Text as needed
import 'package:flutter/material.dart';
import 'package:marquee/marquee.dart';
/// Marquee text along Axis.horizontal for the purpose of the demo.
class MaybeMarqueeText extends StatelessWidget {
final String text;
final double height;
final double maxWidth;
const MaybeMarqueeText(
@rohan20
rohan20 / flutter_google_maps_bottom_sheet.dart
Last active July 4, 2023 15:38
Flutter Google Maps Bottom Sheet
import 'package:flutter/material.dart';
class GoogleMapsClonePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
CustomGoogleMap(),
CustomHeader(),
@rohan20
rohan20 / rounded_border_on_some_sides_widget.dart
Created December 27, 2021 09:26
Colored rounded border on some sides of a Flutter widget
/// Rounded border on some sides of a widget is tricky to achieve since Flutter's [BorderRadius] and [Border] don't
/// work together when the border is "not" on all sides.
///
/// The initial logic was found here: https://stackoverflow.com/a/61613471/5066615.
///
/// The way it's done here is to wrap the [child] in 2 [Container] widgets:
/// The outer [Container] has its background color set to [borderColor] i.e. what we want the border color to be.
/// The inner [Container] has its background color set to the background color of the widget behind the [child] so
/// that it appears to just have a border of [borderColor].
/// The inner [Container] also has a margin that is the same size as the [borderWidth].
@rohan20
rohan20 / sound_null_safety_progress.py
Created January 6, 2023 15:36
measure-flutter-dart-sound-null-safety-migration-progress
# Measures sound-null-safety migration progress.
#
# Does so by checking total number of dart files and number of Dart files with the either of the following 3 statements:
# - "// @dart=2.9"
# - "// ignore: import_of_legacy_library_into_null_safe"
# - "// ignore_for_file: import_of_legacy_library_into_null_safe"
import itertools
import os
import sys
@rohan20
rohan20 / main.dart
Last active October 19, 2022 15:22
Flutter Panable/Moveable/Draggable Widget
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Stack(
children: [
PanableWidget(),
],
),
@rohan20
rohan20 / main.dart
Created August 5, 2022 21:18
Pretty print JSON in Dart
import 'dart:convert' show JsonEncoder;
void prettyPrintJson(dynamic object) {
print(JsonEncoder.withIndent(" ").convert(object));
}
@rohan20
rohan20 / league_table_widget.dart
Created August 3, 2022 22:05
LinkedScrollController Flutter example
const double _rankWidth = 50;
const double _teamInfoWidth = 90;
const double _ptsWidth = cellWidth; // cellWidth is 60 (from another file)
class _LeagueTable extends StatefulWidget {
final List<LeagueTableTeam> leagueTableTeams;
const _LeagueTable({required this.leagueTableTeams, Key? key}) : super(key: key);
@override
@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);
@rohan20
rohan20 / main.dart
Last active December 27, 2021 09:56
[Demo] Colored rounded border on some sides of a Flutter widget
// Initially posted here (with screenshots): https://gist.github.com/rohan20/d12a709a27511304c853334dd636ba63
// Demo: https://dartpad.dev/?id=b95177ad365c4c0e2f48625f27996d52
import 'package:flutter/material.dart';
void main() {
runApp(DemoApp());
}
class DemoApp extends StatelessWidget {