Created
April 19, 2022 05:16
-
-
Save tranductam2802/f11a869842c5570d752150a127dc6547 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(const App()); | |
} | |
class App extends StatelessWidget { | |
const App({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return const MaterialApp( | |
home: StatefulPage(), | |
); | |
} | |
} | |
class StatefulPage extends StatefulWidget { | |
const StatefulPage({Key? key}) : super(key: key); | |
@override | |
StatefulPageState createState() => StatefulPageState(); | |
} | |
class StatefulPageState extends State<StatefulPage> { | |
bool isRow = false; | |
static const List<Widget> childrenConst = [ | |
StatefulConst(), | |
StatelessConst(), | |
]; | |
@override | |
Widget build(BuildContext context) { | |
print('Build: StatefulPageState'); | |
return Scaffold( | |
appBar: AppBar(title: const Text('Sample const')), | |
body: Center( | |
child: isRow | |
? Column(children: childrenConst) | |
: Row(children: childrenConst), | |
), | |
floatingActionButton: FloatingActionButton( | |
child: const Icon(Icons.add), | |
onPressed: () => setState(() { | |
isRow = !isRow; | |
}), | |
), | |
); | |
} | |
} | |
class StatefulConst extends StatefulWidget { | |
const StatefulConst({Key? key}) : super(key: key); | |
@override | |
StatefulConstState createState() => StatefulConstState(); | |
} | |
class StatefulConstState extends State<StatefulConst> { | |
@override | |
Widget build(BuildContext context) { | |
print('Build: StatefulConstState'); | |
return Container( | |
width: 10, | |
height: 10, | |
color: Colors.amber, | |
); | |
} | |
} | |
class StatelessConst extends StatelessWidget { | |
const StatelessConst({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
print('Build: StatelessConst'); | |
return Container( | |
width: 10, | |
height: 10, | |
color: Colors.purple, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment