0

Hello my button's onPressed function is giving error (null is working). Any idea why? Below is the code. The first image asset is wrapped inside an IconButton and I wrote its onPressed property as "onPressed: () {}, thanks " but it is giving Dart error.

import 'package:flutter/material.dart';

class MyQuickModePages extends StatelessWidget {
  const MyQuickModePages({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: const <Widget>[
        Expanded(
          child: Padding(
            padding: EdgeInsets.all(10.0),
            child: IconButton(iconSize: 200,
              icon:  Image(
                  image: AssetImage("assets/images/quickmode/quickmode_q3.jpeg",),
              ),
              onPressed: () {},
            ),
            ),
          ),
        Expanded(child: Padding(
          padding: EdgeInsets.all(10.0),
          child: Image(
            image: AssetImage("assets/images/quickmode/quickmode_q5.jpeg",),
          ),
        ),
        )
      ],
    );
  }
}
Peter Koltai
  • 8,296
  • 2
  • 10
  • 20

2 Answers2

0

Remove const keyword from here:

children: const <Widget>
Peter Koltai
  • 8,296
  • 2
  • 10
  • 20
0

Inside your code, remove const

children: const <Widget> -----> children: <Widget>

Now onPressed: () {} works just fine

Rakesh R
  • 695
  • 7
  • 18