Can't get button press to work in flutter

can synonym
can meaning
can noun meaning
can you
cant
can.'' acronym
meaning of can in hindi
cane meaning

Ok I'm pretty new to flutter/ dart so go easy on me. I'm just trying to make a very simple app where when you press a button some text updates telling you how many times you have pressed the button. I have no idea why this code doesn't work. The button appears but nothing happens when you press it.

import 'package:flutter/material.dart';

class Homepage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Column(
      children: <Widget>[],
    );
  }
}

class Buttonz extends StatefulWidget {
  @override
  _ButtonBeingPressed createState() => new _ButtonBeingPressed();
}

class _ButtonBeingPressed extends State<Buttonz> {
  int _timesPressed = 0;
  _buttonWasPressed() {
    setState(() {
      _timesPressed++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Column(children: <Widget>[
     new Center(
          child: new Row(
        children: <Widget>[
          new Text(
              'The button was pressed ' + _timesPressed.toString() + "         
 times"),
          new RaisedButton(
            onPressed: _buttonWasPressed(),
           child: new Row(
              children: <Widget>[new Text("Press meh")],
            ),
          ),
        ],
      ))
    ]);
  }
}

Your problem is that you didn't pass a callback to RaisedButton, you invoked your callback.

new RaisedButton(
  onPressed: _buttonWasPressed(), // invokes function
  child: new Row(children: <Widget>[new Text("Press meh")]),
);

To pass a callback to another widget you have two choices:

Pass a tear-off
 new RaisedButton(
   onPressed: _buttonWasPressed, // no `()`,
   child: ...
 )
Pass a closure
 new RaisedButton(
   onPressed: () {
     // do something.
   },
   ..
 )

I Can (Song by Nas), 1.4Used to indicate that something is typically the case. 'antique clocks can seem out of place in modern homes'. More example sentences. Can definition, to be able to; have the ability, power, or skill to: She can solve the problem easily, I'm sure. See more.

in some cases, this can occur with a widget in the stack.

It is possible that the Widget is overwritten with another Widget, so it cannot be clicked.

Can (Rock band), Can may refer to: Contents. 1 Containers; 2 Music; 3 Other; 4 See also. Containers[edit]. Aluminum can · Drink can · Oil can · Steel and tin cans · Trash can  Define can. can synonyms, can pronunciation, can translation, English dictionary definition of can. to be able to, have the power or skill to: I can take a bus to the

Added a Material App and rewired the RaisedButton a little. I think it was how you had onPressed wired up.

import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(home: new Buttonz());
  }
}

class Buttonz extends StatefulWidget {
  @override
  _ButtonBeingPressed createState() => new _ButtonBeingPressed();
}

class _ButtonBeingPressed extends State<Buttonz> {
  int _timesPressed = 0;
  _buttonWasPressed() {
    setState(() {
      _timesPressed++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return  new Column(
      children: <Widget>[
        new Text(
            'The button was pressed $_timesPressed times'),
        new RaisedButton(
          child: const Text('Press meh'),
          onPressed: () {
            _buttonWasPressed();
          },
        ),
      ],
    );
  }
}

Can, VerbEdit. can (third-person singular simple present can, present participle -, simple past could, past participle (obsolete except in adjectival use) couth). 110 synonyms of can from the Merriam-Webster Thesaurus, plus 97 related words, definitions, and antonyms. Find another word for can. Can: to bring (as an action or operation) to an immediate end.

Your button should be like this.:

new RaisedButton( 
    child: const Text('Press meh'), 
    onPressed: _buttonWasPressed, 
),

If this doesn't work, then try to clean your flutter project with flutter clean and then reinstalling the app on debug device.

CAN, A can is a metal container in which something such as food, drink, or paint is put. The container is usually sealed to keep the contents fresh. Several young men  can definition: The definition of a can is a container normally made of metal with a lid. (noun) An example of can is what tuna comes in.

Can, can meaning, definition, what is can: to be able to do something or to know ho: Learn more. A Controller Area Network (CAN bus) is a robust vehicle bus standard designed to allow microcontrollers and devices to communicate with each other's applications without a host computer. It is a message-based protocol , designed originally for multiplex electrical wiring within automobiles to save on copper, but can also be used in many other

Nas - I Can (Official Video), can. (kæn). n. 1. a container, esp for liquids, usually of thin sheet metal: a petrol can;  Can (stylised as CAN) was a German experimental rock band formed in Cologne in 1968 by the core quartet of Holger Czukay (bass, tape editing), Irmin Schmidt (keyboards), Michael Karoli (guitar), and Jaki Liebezeit (drums).

Can, We would like to show you a description here but the site won’t allow us.

Comments
  • Having Center in Column is of no use. Rather use Column in Center.
  • It worked. I understand it now. Thank you so much for the help!
  • if it happen, then how will you solve it? coz it happens to me now, tq