Last active
November 13, 2022 13:33
-
-
Save SuperPenguin/347e7b12b7bc1845a84ca551c44d063d to your computer and use it in GitHub Desktop.
dont
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({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
routes: { | |
'/': (context) => const HomeScreen(), | |
}, | |
); | |
} | |
} | |
class HomeScreen extends StatefulWidget { | |
const HomeScreen({super.key}); | |
@override | |
State<HomeScreen> createState() => _HomeScreenState(); | |
} | |
class _HomeScreenState extends State<HomeScreen> { | |
int _counter = 0; | |
List<Widget> _children = []; | |
@override | |
void initState() { | |
super.initState(); | |
_children = [ | |
MyText(count: _counter), | |
]; | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text( | |
_counter.toString(), | |
), | |
), | |
body: Center( | |
child: Column( | |
mainAxisSize: MainAxisSize.min, | |
children: _children, | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
setState(() { | |
_counter += 1; | |
}); | |
}, | |
child: const Icon(Icons.add), | |
), | |
); | |
} | |
} | |
class MyText extends StatelessWidget { | |
const MyText({ | |
super.key, | |
required this.count, | |
}); | |
final int count; | |
@override | |
Widget build(BuildContext context) { | |
return Text('Count: $count'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment