Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4. runApp(SampleApp());
  5. }
  6.  
  7. class SampleApp extends StatelessWidget {
  8. // This widget is the root of your application.
  9. @override
  10. Widget build(BuildContext context) {
  11. return MaterialApp(
  12. title: 'Sample App',
  13. theme: ThemeData(
  14. primarySwatch: Colors.blue,
  15. ),
  16. home: SampleAppPage(),
  17. );
  18. }
  19. }
  20.  
  21. class SampleAppPage extends StatefulWidget {
  22. SampleAppPage({Key key}) : super(key: key);
  23.  
  24. @override
  25. _SampleAppPageState createState() => _SampleAppPageState();
  26. }
  27.  
  28. class _SampleAppPageState extends State<SampleAppPage> {
  29. // Default value for toggle
  30. bool toggle = true;
  31. void _toggle() {
  32. setState(() {
  33. toggle = !toggle;
  34. });
  35. }
  36.  
  37. _getToggleChild() {
  38. if (toggle) {
  39. return Text('Toggle One');
  40. } else {
  41. return MaterialButton(onPressed: () {}, child: Text('Toggle Two'));
  42. }
  43. }
  44.  
  45. @override
  46. Widget build(BuildContext context) {
  47. return Scaffold(
  48. appBar: AppBar(
  49. title: Text("Sample App"),
  50. ),
  51. body: Center(
  52. child: _getToggleChild(),
  53. ),
  54. floatingActionButton: FloatingActionButton(
  55. onPressed: _toggle,
  56. tooltip: 'Update Text',
  57. child: Icon(Icons.update),
  58. ),
  59. );
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement