Home > database >  Flutter error "Expected to find ']'." at widget
Flutter error "Expected to find ']'." at widget

Time:07-30

I am trying to pass IconButton to a widget. But it is showing the error : Expected to find ']'.
Here is the screenshot of it :

enter image description here

Information on hover :
Expected to find ']'. package:flutter/src/widgets/framework.dart
T get widget

Containing class: State
The current configuration. A State object's configuration is the corresponding StatefulWidget instance. This property is initialized by the framework before calling initState. If the parent updates this location in the tree to a new widget with the same runtimeType and Widget.key as the current configuration, the framework will update this property to refer to the new widget and then call didUpdateWidget, passing the old configuration as an argument.

Code :

import 'package:app15/ui/theme.dart';
import 'package:app15/widgets/input_field.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';

class AddTaskPage extends StatefulWidget {
  const AddTaskPage({Key? key}) : super(key: key);

  @override
  State<AddTaskPage> createState() => _AddTaskPageState();
}

class _AddTaskPageState extends State<AddTaskPage> {
  DateTime _selectedDate = DateTime.now();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: _appBar(context),
      body: Container(
        padding: const EdgeInsets.only(left: 20, right: 20),
        child: SingleChildScrollView(
          child: Column(
            children: [
              Text(
                "Add Task",
                style: headingStyle,
              ),
              MyInputField(title: "Title", hint: "Enter your title"),
              MyInputField(title: "Note", hint: "Enter your note"),
              MyInputField(title: "Date", hint: DateFormat.yMd().format(_selectedDate)),
              widget: IconButton(                    //===> Here it shows the error
                icon: Icon(icons.calendar_today_outlined),
                onPressed: () {

                },
              )
            ],
          ),
        )
      ),
    );
  }

  _appBar(BuildContext context) {
    return AppBar(
      elevation: 0,
      //backgroundColor: ,
      leading: GestureDetector(
        onTap: (){
          Get.back();
        },
        child: Icon(
          Icons.arrow_back_ios,
          size: 20,
          color: Colors.black,
        ),
      ),
    );
  }
}

CodePudding user response:

There is no widget attribute inside the list children.

Text(
   "Add Task",
      style: headingStyle,
   ),
   MyInputField(title: "Title", hint: "Enter your title"),
   MyInputField(title: "Note", hint: "Enter your note"),
   MyInputField(title: "Date", hint: DateFormat.yMd().format(_selectedDate)),
   IconButton(                    //===> remove Widget:
     icon: Icon(Icons.calendar_today_outlined),
     onPressed: () {},
   ),
  • Related