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
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 / 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 {
@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_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_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();
@letsar
letsar / slidable_in_depth_05.dart
Created August 24, 2018 13:44
slidable_in_depth_05
// For the main actions we have to reverse the order if we want the last item at the bottom of the stack.
int displayIndex = showActions ? count - index - 1 : index;
return ctx.createPositioned(
position: animations[index].value,
extent: actionExtent,
child: actionDelegate.build(context, displayIndex,
actionsMoveAnimation, SlidableRenderingMode.slide),
);
SlidableDrawerDelegateAnimation({
Key key,
this.controller,
}) : dxPositions = <Animation<Offset>>[
Tween<Offset>(
begin: Offset(-1.0, 0.0),
end: Offset(1.0, 0.0),
).animate(
CurvedAnimation(
parent: controller,
class SlidableDrawerDelegateDemo extends StatefulWidget {
@override
_SlidableDrawerDelegateDemoState createState() =>
new _SlidableDrawerDelegateDemoState();
}
class _SlidableDrawerDelegateDemoState extends State<SlidableDrawerDelegateDemo>
with TickerProviderStateMixin {
AnimationController _controller;