Created with <3 with dartpad.dev.
Last active
April 14, 2023 14:31
-
-
Save aliyazdi75/427d2006f3fc8b1afc27adef6bf7b057 to your computer and use it in GitHub Desktop.
Bad Structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 StatefulWidget { | |
final String title; | |
const MyHomePage({ | |
Key? key, | |
required this.title, | |
}) : super(key: key); | |
@override | |
State<MyHomePage> createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
int _counterGreen = 0; | |
int _counterRed = 0; | |
void _incrementCounterGreen() { | |
setState(() { | |
_counterGreen++; | |
}); | |
} | |
void _incrementCounterRed() { | |
setState(() { | |
_counterRed++; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Text( | |
'You have pushed the Green button this many times:', | |
), | |
Text( | |
'$_counterGreen', | |
style: Theme.of(context) | |
.textTheme | |
.headlineMedium! | |
.copyWith(color: Colors.green), | |
), | |
Text( | |
'You have pushed the Red button this many times:', | |
), | |
Text( | |
'$_counterRed', | |
style: Theme.of(context) | |
.textTheme | |
.headlineMedium! | |
.copyWith(color: Colors.red), | |
), | |
], | |
), | |
), | |
floatingActionButton: Column( | |
mainAxisSize: MainAxisSize.min, | |
children: [ | |
FloatingActionButton( | |
onPressed: _incrementCounterGreen, | |
tooltip: 'Increment Green', | |
backgroundColor: Colors.green, | |
child: Icon(Icons.add), | |
), | |
FloatingActionButton( | |
onPressed: _incrementCounterRed, | |
tooltip: 'Increment Red', | |
backgroundColor: Colors.red, | |
child: Icon(Icons.add), | |
), | |
], | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 StatefulWidget { | |
final String title; | |
const MyHomePage({ | |
Key? key, | |
required this.title, | |
}) : super(key: key); | |
@override | |
State<MyHomePage> createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
int _counterGreen = 0; | |
int _counterRed = 0; | |
void _incrementCounterGreen() { | |
setState(() { | |
_counterGreen++; | |
}); | |
} | |
void _incrementCounterRed() { | |
setState(() { | |
_counterRed++; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Text( | |
'You have pushed the Green button this many times:', | |
), | |
Text( | |
'$_counterGreen', | |
style: Theme.of(context) | |
.textTheme | |
.headlineMedium! | |
.copyWith(color: Colors.green), | |
), | |
Text( | |
'You have pushed the Red button this many times:', | |
), | |
Text( | |
'$_counterRed', | |
style: Theme.of(context) | |
.textTheme | |
.headlineMedium! | |
.copyWith(color: Colors.red), | |
), | |
], | |
), | |
), | |
floatingActionButton: Column( | |
mainAxisSize: MainAxisSize.min, | |
children: [ | |
FloatingActionButton( | |
onPressed: _incrementCounterGreen, | |
tooltip: 'Increment Green', | |
backgroundColor: Colors.green, | |
child: Icon(Icons.add), | |
), | |
FloatingActionButton( | |
onPressed: _incrementCounterRed, | |
tooltip: 'Increment Red', | |
backgroundColor: Colors.red, | |
child: Icon(Icons.add), | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment