Last active
March 11, 2021 11:01
-
-
Save mihalycsaba/e98d4a81007c1564569aee86c82348c1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(MaterialApp( | |
title: 'Flutter Tutorial', | |
home: TutorialHome(), | |
)); | |
} | |
class TutorialHome extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
// Scaffold is a layout for the major Material Components. | |
return Scaffold( | |
appBar: AppBar( | |
leading: IconButton( | |
icon: Icon(Icons.menu), | |
tooltip: 'Navigation menu', | |
onPressed: null, | |
), | |
title: Text('Example title'), | |
actions: <Widget>[ | |
IconButton( | |
icon: Icon(Icons.search), | |
tooltip: 'Search', | |
onPressed: null, | |
), | |
], | |
), | |
// body is the majority of the screen. | |
body: Counter(), | |
floatingActionButton: FloatingActionButton( | |
tooltip: 'Add', // used by assistive technologies | |
child: Icon(Icons.add), | |
onPressed: null, | |
), | |
); | |
} | |
} | |
class CounterDisplay extends StatelessWidget { | |
CounterDisplay({this.count}); | |
final int count; | |
@override | |
Widget build(BuildContext context) { | |
return Text('Count: $count'); | |
} | |
} | |
class CounterIncrementor extends StatelessWidget { | |
CounterIncrementor({this.onPressed}); | |
final VoidCallback onPressed; | |
@override | |
Widget build(BuildContext context) { | |
return RaisedButton( | |
onPressed: onPressed, | |
child: Text('Increment'), | |
); | |
} | |
} | |
class Counter extends StatefulWidget { | |
@override | |
_CounterState createState() => _CounterState(); | |
} | |
class _CounterState extends State<Counter> { | |
int _counter = 0; | |
void _increment() { | |
setState(() { | |
++_counter; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Row(children: <Widget>[ | |
CounterIncrementor(onPressed: _increment), | |
CounterDisplay(count: _counter), | |
]); | |
} | |
} | |
class MyButton extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return GestureDetector( | |
onTap: () { | |
print('MyButton was tapped!'); | |
}, | |
child: Container( | |
height: 36.0, | |
padding: const EdgeInsets.all(8.0), | |
margin: const EdgeInsets.symmetric(horizontal: 8.0), | |
decoration: BoxDecoration( | |
borderRadius: BorderRadius.circular(5.0), | |
color: Colors.lightGreen[500], | |
), | |
child: Center( | |
child: Text('Engage'), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment