Skip to content

Instantly share code, notes, and snippets.

@hectorAguero
Last active July 13, 2023 02:47
Show Gist options
  • Save hectorAguero/b8a31b2a5fce06ff868164dd450ebbb2 to your computer and use it in GitHub Desktop.
Save hectorAguero/b8a31b2a5fce06ff868164dd450ebbb2 to your computer and use it in GitHub Desktop.
Flutter / Dart const info linter error
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