Last active
May 9, 2024 00:00
-
-
Save yjbanov/560171695b59cc8f0356f40443703ee7 to your computer and use it in GitHub Desktop.
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(const MyApp(name: 'Dash')); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key, required this.name}); | |
final String name; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Counter( | |
name: name, | |
startValue: 10, | |
), | |
); | |
} | |
} | |
// @State('int count = 0') | |
class Counter extends GeneratedStatefulWidget<_GeneratedCounterState> { | |
const Counter({super.key, required this.name, required this.startValue}); | |
final String name; | |
final int startValue; | |
@override | |
Widget build(state) { | |
return Scaffold( | |
appBar: AppBar(title: Text('Hello $name')), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
state.count += 1; | |
}, | |
), | |
body: Center( | |
child: Text('Count: ${startValue + state.count}'), | |
), | |
); | |
} | |
//////////////// GENERATED /////////////////////////// | |
@override | |
State<StatefulWidget> createState() => _GeneratedCounterState(); | |
} | |
abstract class GeneratedStatefulWidget<S extends State> extends StatefulWidget { | |
const GeneratedStatefulWidget({super.key}); | |
Widget build(S state); | |
} | |
class _GeneratedCounterState extends State<Counter> { | |
int get count => _count; | |
set count(int value) { | |
setState(() { | |
_count = value; | |
}); | |
} | |
int _count = 0; | |
@override | |
Widget build(BuildContext context) { | |
return widget.build(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment