Skip to content

Instantly share code, notes, and snippets.

@AdnanKhan45
Last active July 9, 2023 15:22
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 AdnanKhan45/7fa14b6387abbd889d858712fb9c33fb to your computer and use it in GitHub Desktop.
Save AdnanKhan45/7fa14b6387abbd889d858712fb9c33fb to your computer and use it in GitHub Desktop.
The complete code of example how flutter render widgets.
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