Last active
July 13, 2023 02:47
-
-
Save hectorAguero/b8a31b2a5fce06ff868164dd450ebbb2 to your computer and use it in GitHub Desktop.
Flutter / Dart const info linter error
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()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return const MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: MyHomeBody(myList: []), | |
), | |
), | |
); | |
} | |
} | |
class MyHomeBody extends StatefulWidget { | |
const MyHomeBody({super.key, required this.myList}); | |
final List<String> myList; | |
@override | |
State<MyHomeBody> createState() => _MyHomeBodyState(); | |
} | |
class _MyHomeBodyState extends State<MyHomeBody> { | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
for (final text in widget.myList) Text(text), | |
ElevatedButton( | |
onPressed: () { | |
setState(() { | |
widget.myList.add('1'); | |
}); | |
}, | |
child: Text( | |
'Console Error Button', | |
style: Theme.of(context).textTheme.headlineMedium, | |
), | |
), | |
const SizedBox(height: 8), | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment