2

通过阅读文档,我确信这是很好的声明,但添加图标仍然是灰色的。

 class _TaskState extends State<Task> {    
       @override
       Widget build(BuildContext context) {
    



     return Scaffold(
           

appBar: AppBar(
             backgroundColor: Colors.red,
             title: Text('Tasks'),
             centerTitle: true,
             actions: <Widget>[
               IconButton(
                 icon: Icon(Icons.add),
                 color: Colors.white,
                 iconSize: 32.0,
                   ),
                 ],
               ),
               drawer: TheDrawer()
             );
           }
         }
4

1 回答 1

5

注意 linter 警告。您没有传递构造函数onPressed所需的参数IconButton

添加它应该可以解决您的问题。

import 'package:flutter/material.dart';

final Color darkBlue = Color.fromARGB(255, 18, 32, 47);

void main() {
  runApp(Task());
}

class Task extends StatefulWidget {
    @override
    _TaskState createState() => _TaskState();
}
    
class _TaskState extends State {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.red,
        title: Text('Tasks'),
        centerTitle: true,
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.add),
            color: Colors.white,
            iconSize: 32.0,
            onPressed: () {
              
            }
          ),
        ],
      ),
    );
  }
}

onPressed回调为null时,它会IconButton自动变灰以指示该按钮已禁用。有关更多信息,请参阅文档

于 2020-06-29T18:14:39.337 回答