Skip to content

Instantly share code, notes, and snippets.

@rrousselGit
Last active December 8, 2019 12:22
Show Gist options
  • Save rrousselGit/c6cd1df090e0cd8d97a5a344b36bd8fa to your computer and use it in GitHub Desktop.
Save rrousselGit/c6cd1df090e0cd8d97a5a344b36bd8fa to your computer and use it in GitHub Desktop.
// 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: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
Widget build(covariant _MyHomePageState context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'${context.count}',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: context._incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
@override
_MyHomePageState createElement() => _MyHomePageState(this);
}
class _MyHomePageState extends StatelessElement {
_MyHomePageState(MyHomePage widget) : super(widget);
@override
MyHomePage get widget => super.widget;
int count = 0;
void _incrementCounter() {
count++;
markNeedsBuild();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment