Skip to content

Instantly share code, notes, and snippets.

View letsar's full-sized avatar
🦋
Flutter forever

Romain Rastel letsar

🦋
Flutter forever
View GitHub Profile
@letsar
letsar / variable_sized_grid_view.dart
Last active January 31, 2023 22:54
VariableSizedGridView for Flutter (Masonry style)
import 'dart:math' as math;
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
/// Signature for a function that creates a [TileSize] for a given index.
typedef TileSize IndexedTileSizeBuilder(int index);
/// Creates grid layouts with a fixed number of spans in the cross axis.
@letsar
letsar / inherited_widget_test.dart
Created January 10, 2018 19:26
Flutter InheritedWidget test
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';
void main() {
runApp(new AppContainer());
}
class AppContextData {
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(
Widget build(BuildContext context) =>
Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
@letsar
letsar / staggered_grid_example_01.dart
Last active February 27, 2020 04:08
Staggered grid example
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
List<StaggeredTile> _staggeredTiles = const <StaggeredTile>[
const StaggeredTile.count(2, 2),
const StaggeredTile.count(2, 1),
const StaggeredTile.count(1, 2),
const StaggeredTile.count(1, 1),
const StaggeredTile.count(2, 2),
const StaggeredTile.count(1, 2),
@letsar
letsar / tab_bar_view.dart
Created June 30, 2018 12:31
How to use a SliverStickyHeader inside a TabBarView
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_sticky_header/flutter_sticky_header.dart';
class _Page {
const _Page(
this.id,
this.title,
this.color,
@letsar
letsar / slidable_in_depth_01.dart
Last active August 24, 2018 13:39
slidable_in_depth_01
abstract class SlidableStackDelegate extends SlidableDelegate {
const SlidableStackDelegate({
double fastThreshold,
}) : super(fastThreshold: fastThreshold);
@override
Widget buildActions(BuildContext context, SlidableDelegateContext ctx) {
final animation = new Tween(
begin: Offset.zero,
end: ctx.createOffset(ctx.state.totalActionsExtent * ctx.state.dragSign),
@letsar
letsar / slidable_in_depth_02.dart
Last active August 24, 2018 13:38
slidable_in_depth_02
Widget buildStackActions(BuildContext context, SlidableDelegateContext ctx) {
return new Positioned.fill(
child: new LayoutBuilder(builder: (context, constraints) {
final state = ctx.state;
final count = state.actionCount;
final bool showActions = ctx.showActions;
final Animation<double> actionsMoveAnimation =
state.actionsMoveAnimation;
final double actionExtent =
ctx.getMaxExtent(constraints) * state.widget.actionExtentRatio;
@letsar
letsar / slidable_in_depth_03.dart
Last active August 24, 2018 13:40
slidable_in_depth_03
final double actionExtent =
ctx.getMaxExtent(constraints) * state.widget.actionExtentRatio;
@letsar
letsar / slidable_in_depth_04.dart
Last active August 24, 2018 13:41
slidable_in_depth_04
final animations = Iterable.generate(count).map((index) {
return new Tween(
begin: -actionExtent,
end: (count - index - 1) * actionExtent,
).animate(actionsMoveAnimation);
}).toList();