简体   繁体   中英

Issues with button widgets on flutter

那是我的代码

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 problem comes in your folder test, click in the error and change the name MyApp to FirstApp.

在此处输入图像描述

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM