I am learning flutter/dart. I am not sure why, but when testing my code in code studio, my buttons are not enabled. they are dark and unclickable. I have been trying different things, but it feels like the "onPressed" functions are not working.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
void answerQuestion() {
print('Answer chosen!');
}
@override
Widget build(BuildContext cntx) {
var questions = [
'What\'s your favorite color?',
'What\'s your favorite animal?',
];
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('My First App'),
),
body: Column(
children: [
Text('The question!'),
ElevatedButton(
child: Text('Answer 1'),
onPressed: answerQuestion,
),
ElevatedButton(
child: Text('Answer 2'),
onPressed: () => print('Answer 2 chosen!'),
),
ElevatedButton(
child: Text('Answer 3'),
onPressed: () {
//...
print('Answer 3 chosen');
},
),
],
),
),
);
}
}
`
CodePudding user response:
your code works fine, just make sure hot reload/restart is working
CodePudding user response:
I rebooted my emulator and it's working like a charm! please archive this question