Skip to content

Instantly share code, notes, and snippets.

@slightfoot
slightfoot / anchor_scroll.dart
Last active January 27, 2021 00:28
Ever wanted to scroll down to a widget in a scroll view? Now you can, Anchor Scroll to the rescue! - by Simon Lightfoot - 15/11/2019
// MIT License
//
// Copyright (c) 2019 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:
@lukepighetti
lukepighetti / text_editing_controller_builder.dart
Last active September 27, 2021 20:32
Wrap any TextField with TextEditingControllerBuilder to make it declarative
import 'package:flutter/widgets.dart';
class TextEditingControllerBuilder extends StatefulWidget {
/// Exposes a [TextEditingController] to the child, which allows
/// us to convert any [TextField] into a declarative version.
///
/// Typically used for wiring up many state fields to form inputs
/// and making sure everything stays in sync.
///
/// If [text] is updated, the consuming [TextField] will also be updated.
# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
#
# Google internally enforced rules. See README.md for more information,
# including a list of lints that are intentionally _not_ enforced.
linter:
rules:
- always_declare_return_types
@flutter-clutter
flutter-clutter / particle.dart
Created July 18, 2020 09:14
Animated sparkler in Flutter
import 'dart:math';
import 'package:flutter/material.dart';
class Particle extends StatefulWidget {
Particle({
this.duration = const Duration(milliseconds: 300)
});
final Duration duration;
@override
@slightfoot
slightfoot / transitions_fun.dart
Created January 8, 2020 21:31
Fun with Route Animations - by Simon Lightfoot - #HumpDayQandA - 8th Janurary 2020
// MIT License
//
// Copyright (c) 2019 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:
@escamoteur
escamoteur / nextField.dart
Created September 13, 2019 12:22
So easy is it now to implement a next field behavior for forms, meaning that the focus is moved as soon the user tabs the next button on the keyboard
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
TabController _tabController;
FocusScopeNode _node = FocusScopeNode(); /// <-----------------
@override
void initState() {
_tabController = TabController(length: 3, vsync: this);
@slightfoot
slightfoot / page_turn.dart
Created September 9, 2019 21:28
Page Turn Effect - By Simon Lightfoot. Replicating this behaviour. https://www.youtube.com/watch?v=JqvtZwIJMLo
// MIT License
//
// Copyright (c) 2019 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:
@lukepighetti
lukepighetti / extents_page_view.dart
Last active January 3, 2023 13:48
Flutter PageView that loads the next/previous page off-screen
import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart' hide PageView;
/// This is copy-pasted from the Flutter framework with a support added for building
/// pages off screen using [Viewport.cacheExtents] and a [LayoutBuilder]
///
/// Based on commit 3932ffb1cd5dfa0c3891c60977ee4f9cd70ade66 on channel dev
// Having this global (mutable) page controller is a bit of a hack. We need it
@slightfoot
slightfoot / multi_select.dart
Last active August 3, 2023 18:10
Multi Select GridView in Flutter - by Simon Lightfoot (Drag to select multiple items) Try now here: https://dartpad.dev/?id=a002dd1e031f5f012f810c6d5da14a11
// MIT License
//
// Copyright (c) 2019 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:
@webianks
webianks / main.dart
Created August 23, 2019 11:32
Scanning Animation In Flutter
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:scanning_aimation/scanner.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {