Showmodalbuttom sheet 'Invalid constant value'

82 Views Asked by At

    import 'package:flutter/material.dart';
    import 'package:todoey/screen/tasks_list.dart';

    class TasksScreen extends StatelessWidget {
      
      Widget buildButtomSheet(BuildContext context) {
        return Container();
      }
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          backgroundColor: Colors.lightBlueAccent,
          floatingActionButton:  FloatingActionButton(
            backgroundColor: Colors.lightBlueAccent,
            child: const Icon(Icons.add),
            onPressed: () {
             showModalBottomSheet = showModalBottomSheet(context: context, builder: buildButtomSheet);
        },
          ),
          body: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                padding: const EdgeInsets.only(
                    top: 60.0, left: 30, right: 30, bottom: 30.0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: const <Widget>[
                    CircleAvatar(
                      child: Icon(
                        Icons.list,
                        size: 30,
                        color: Colors.lightBlueAccent,
                      ),
                      backgroundColor: Colors.white,
                      radius: 30,
                    ),
                    SizedBox(height: 10),
                    Text(
                      'Todoey',
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 50,
                        fontWeight: FontWeight.w700,
                      ),
                    ),
                    Text(
                      '12 task',
                      style: TextStyle(
                        color: Colors.white,
                      ),
                    ),
                  ],
                ),
              ),
              Expanded(
                child: Container(
                  padding: const EdgeInsets.symmetric(horizontal: 20),
                  decoration: const BoxDecoration(
                    borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(30.0),
                        topRight: Radius.circular(30)),
                    color: Colors.white,
                  ),
                  child: const TasksList(),
                ),
              ),
            ],
          ),
        );
      }
    }

   child: const Icon(Icons.add),
            onPressed: () {
             showModalBottomSheet = showModalBottomSheet(context: context, builder: buildButtomSheet); 

I had issues with the code line above, i have tried several changes but it still tells "Invalid function".

1

There are 1 best solutions below

8
Md. Yeasin Sheikh On

Remove const from FloatingActionButton, because onPressed method will be called on run time.

floatingActionButton: FloatingActionButton(
  onPressed: () {},
),

More about const

floatingActionButton: FloatingActionButton(
  backgroundColor: Colors.lightBlueAccent,
  child: const Icon(Icons.add),
  onPressed: () async {
    final result = await showModalBottomSheet(
        context: context, builder: buildButtomSheet);
  },
),