Skip to content

Instantly share code, notes, and snippets.

@lukepighetti
Last active March 16, 2020 19:33
Show Gist options
  • Select an option

  • Save lukepighetti/1e5cdbea51b6820f4ed11c006fb31827 to your computer and use it in GitHub Desktop.

Select an option

Save lukepighetti/1e5cdbea51b6820f4ed11c006fb31827 to your computer and use it in GitHub Desktop.
Extensions don't fuck anything up
// 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.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Material(
child: Foo().nudge(x: 50),
),
);
}
}
class Foo extends StatelessWidget {
Foo(){
print("instantiated Foo"); // fires once
}
@override
build(BuildContext context) {
return Text("Foo!");
}
}
extension on Widget {
nudge({double x = 0, double y = 0}) =>
Transform.translate(offset: Offset(x, y), child: this);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment