So I am new to flutter and I was trying to tie a function to button widgets on flutter. It did not work and I honestly do not know why. I put my code in the picture and I would also copy and paste the code below.
//ignore_for_file: deprecated_member_use
import 'package:flutter/material.dart';
void main() => runApp(FirstApp());
class FirstApp extends StatelessWidget {
void answerQuestion(){
print ('Question answered!');
}
@override
Widget build(BuildContext context) {
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: answerQuestion),
ElevatedButton(child: Text('Answer 3'), onPressed: answerQuestion),
],
),
),
);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.