The complete code of example how flutter render widgets : Learn how Flutter render widgets
Last active
July 9, 2023 15:22
-
-
Save AdnanKhan45/7fa14b6387abbd889d858712fb9c33fb to your computer and use it in GitHub Desktop.
The complete code of example how flutter render widgets.
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 { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark(useMaterial3: true), | |
home: HomePage(), | |
); | |
} | |
} | |
class HomePage extends StatefulWidget { | |
const HomePage({Key? key}) : super(key: key); | |
@override | |
State<HomePage> createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> { | |
bool _switchTree = false; | |
Widget get firstTree => Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Text("Flutter is awesome <3", style: TextStyle(fontSize: 35),), | |
SizedBox(width: 10,), | |
], | |
); | |
Widget get secondTree => Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Text("Dart is awesome <3", style: TextStyle(fontSize: 35),), | |
Padding(padding: EdgeInsets.only(right: 10),), | |
], | |
); | |
Widget get switchButton => Padding( | |
padding: EdgeInsets.only(bottom: 20), | |
child: ElevatedButton( | |
onPressed: () { | |
setState(() { | |
_switchTree = !_switchTree; | |
}); | |
}, | |
child: Text("Switch Tree"), | |
), | |
); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
_switchTree ? firstTree : secondTree, | |
SizedBox(height: 10,), | |
switchButton | |
], | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment