Skip to content

Instantly share code, notes, and snippets.

@e16din
Last active July 23, 2023 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e16din/b46ec8132e2b189bee005869a7ed112d to your computer and use it in GitHub Desktop.
Save e16din/b46ec8132e2b189bee005869a7ed112d to your computer and use it in GitHub Desktop.
My First App
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My First Flutter App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('My First Flutter App'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
style: TextStyle(color: Colors.redAccent),
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium!.copyWith(color: Colors.redAccent),
),
if (_counter == 10)
Text(
'Congratulations! You reached 10!',
style: TextStyle(color: Colors.greenAccent, fontSize: 24),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
backgroundColor: Colors.redAccent,
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment