Home > Mobile >  How to fix IconButton onPressed property?
How to fix IconButton onPressed property?

Time:08-10

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",),
          ),
        ),
        )
      ],
    );
  }
}

CodePudding user response:

Remove const keyword from here:

children: const <Widget>

CodePudding user response:

Inside your code, remove const

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

Now onPressed: () {} works just fine

  • Related