Skip to content

Instantly share code, notes, and snippets.

View flutter9.dart
class MyScaffold extends HookWidget {
const MyScaffold({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final theme = useTheme();
final currentPage = usePage();
final count = useState(0);
View flutter8.dart
import 'package:provider/provider.dart';
enum Page { counter, settings }
class MyApp extends HookWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final currentPage = useState(Page.counter);
View flutter7.dart
ThemeData useTheme() => Theme.of(useContext());
class MyScaffold extends HookWidget {
const MyScaffold({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final count = useState(0);
final theme = useTheme();
View flutter6.dart
class MyScaffold extends HookWidget {
const MyScaffold({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final count = useState(0);
final theme = Theme.of(context);
return Scaffold(
appBar: AppBar(title: Text('Title')),
View flutter6.dart
import 'package:flutter_hooks/flutter_hooks.dart';
class MyScaffold extends HookWidget {
const MyScaffold({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final count = useState(0);
return Scaffold(
appBar: AppBar(title: Text('Title')),
View flutter5.dart
class MyButton extends StatelessWidget {
const MyButton({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
print('MyButton was tapped!');
},
child: Container(
View flutter4.dart
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(home: MyScaffold());
}
}
View flutter3.dart
void main() {
runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Title')),
body: Text('Hello World'),
floatingActionButton: FloatingActionButton(
onPressed: () => print('Button pressed'),
child: Icon(Icons.add),
),
@kasperpeulen
kasperpeulen / gist2.dart
Created Nov 26, 2021
Providing context
View gist2.dart
import 'package:flutter/widgets.dart';
void main() {
runApp(
Directionality(
textDirection: TextDirection.ltr,
child: Text('Hello World!'),
),
);
}
View flutter1.dart
import 'package:flutter/widgets.dart';
void main() {
runApp(Text('Hello World!'));
}