Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for a simple "counter" example in Tutorial #35

Closed
sethladd opened this issue Oct 30, 2015 · 7 comments
Closed

Request for a simple "counter" example in Tutorial #35

sethladd opened this issue Oct 30, 2015 · 7 comments
Assignees
Labels
a.tut.tutorial Relates to the Tutorial section of docs.flutter.dev

Comments

@sethladd
Copy link
Contributor

Working through the tutorial, I felt myself really wanting to see the most basic example of some UI changing its state. Perhaps a "counter" with a button, which when pressed, updates the count of some text.

IMHO, the Shopping Cart is a bit too complex as an example to show why we need StatefulComponents.

I'd be happy to help write this section if someone wants to contribute the canonical, simple "counter".

Thanks!

@sethladd sethladd added the a.tut.tutorial Relates to the Tutorial section of docs.flutter.dev label Oct 30, 2015
@abarth
Copy link
Contributor

abarth commented Oct 30, 2015

As simple counter might look something like the following (warning: I haven't tried running this example):

class Counter extends StatefulComponent {
  Counter({ Key key }) : super(key: key);
  _CounterState createState() => new _CounterState();
}

class _CounterState extends State<Counter> {
  int _count = 0;

  void _increment() {
    setState(() { ++_count; });
  }

  Widget build(BuildContext context) {
    return new Row([
      new RaisedButton(
        onPressed: _increment,
        child: new Text('Increment')
      ),
      new Text('Count: $_count')
    ]);
  }
}

@sethladd
Copy link
Contributor Author

Thanks!

here's another one from @HansMuller

import 'package:flutter/material.dart';

class StatefulDemo extends StatefulComponent {
  StatefulDemoState createState() => new StatefulDemoState();
}

class StatefulDemoState extends State<StatefulDemo> {
  int _counter = 0;

  Widget build(BuildContext context) {
    return new Center(
      child: new RaisedButton(
        child: new Text("Click $_counter"),
        onPressed: () {
          setState(() { _counter += 1; });
        }
      )
    );
  }
}

void main() {
  runApp(new StatefulDemo());
}

For the sake of the tutorial, at this step in the learning process, I'd like to avoid a mention of key. Are we OK with Counter not having that constructor?

@krisgiesing
Copy link
Contributor

I would slightly prefer an example where the object that builds the display of the counter is different from the object that triggers the counter increment. It's not very much more code and it would illustrate separation of concern a little better than having it all be in one place. What do you think?

@abarth
Copy link
Contributor

abarth commented Oct 30, 2015

Are we OK with Counter not having that constructor?

That's fine with me.

@sethladd
Copy link
Contributor Author

@krisgiesing : great idea. Your example would be a natural "step two", after we show this simple Counter. Did you want to code up a "refactor" of the Counter? It tells a nice story.

@krisgiesing
Copy link
Contributor

Sure.

On Fri, Oct 30, 2015 at 11:16 AM, Seth Ladd notifications@github.com
wrote:

@krisgiesing https://github.com/krisgiesing : great idea. Your example
would be a natural "step two", after we show this simple Counter. Did you
want to code up a "refactor" of the Counter? It tells a nice story.


Reply to this email directly or view it on GitHub
https://github.com/flutter/flutter.github.io/issues/35#issuecomment-152607032
.

krisgiesing added a commit to krisgiesing/flutter.github.io that referenced this issue Nov 3, 2015
krisgiesing added a commit that referenced this issue Nov 3, 2015
Fix #35: Add simpler example of state manipulation
@sethladd
Copy link
Contributor Author

sethladd commented Nov 3, 2015

Thanks @krisgiesing !

techhtml referenced this issue in flutter-korea/website May 29, 2019
cookbook/navigation/passing-data 초벌 번역
khanhnwin added a commit that referenced this issue May 11, 2022
khanhnwin added a commit that referenced this issue May 11, 2022
* Bump actions/checkout from 3.0.1 to 3.0.2 (#4)

* Bring secret repo up to date with frozen flutter/website repo (#11)

* [Content update] src/get-started/flutter-for/web-devs.md (#7042)

* src/get-started/flutter-for/web-devs.md

* Add the trailing `s` suggested by @domesticmouse

* Apply the style suggestion from @parlough

* Unblock updates of firebase-cli. (#7040)

This will also unblock the automatic update of multiple npm packages.

* [Content update] src/get-started/flutter-for/xamarin-forms-devs.md (#7045)

* src/get-started/flutter-for/xamarin-forms-devs.md

* Update src/get-started/flutter-for/xamarin-forms-devs.md

* Update src/get-started/flutter-for/xamarin-forms-devs.md

* Update src/get-started/flutter-for/xamarin-forms-devs.md

* Update src/get-started/flutter-for/xamarin-forms-devs.md

Co-authored-by: Shams Zakhour (ignore Sfshaza) <44418985+sfshaza2@users.noreply.github.com>

* Add design document link for PSC (#7046)

* Update dart tool info (#7049)

* Bump firebase-tools from 10.6.0 to 10.7.0 (#7051)

Bumps [firebase-tools](https://github.com/firebase/firebase-tools) from 10.6.0 to 10.7.0.
- [Release notes](https://github.com/firebase/firebase-tools/releases)
- [Commits](firebase/firebase-tools@v10.6.0...v10.7.0)

---
updated-dependencies:
- dependency-name: firebase-tools
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Upgrade `layout-basics.md` (#7047)

fixes: #7006

* Add post-install fix for nokogiri aarch in setup (#7055)

* Added Desktop/macOS job listing (#7053)

* Added Desktop/macOS job listing

* Update src/jobs/macos.md

* Update src/jobs/macos.md

* Update src/jobs/macos.md

Co-authored-by: Shams Zakhour (ignore Sfshaza) <44418985+sfshaza2@users.noreply.github.com>

* Bump actions/checkout from 3.0.1 to 3.0.2 (#7057)

* Update firebase.json (#6884)

* add website freeze warning to PR template (#7058)

* Bump firebase-tools from 10.7.0 to 10.7.1 (#7056)

Bumps [firebase-tools](https://github.com/firebase/firebase-tools) from 10.7.0 to 10.7.1.
- [Release notes](https://github.com/firebase/firebase-tools/releases)
- [Commits](firebase/firebase-tools@v10.7.0...v10.7.1)

---
updated-dependencies:
- dependency-name: firebase-tools
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* replace launch (deprecated) with launchUrl (#7062)

* replace launch (deprecated) with launchUrl

* refresh excerpts

* Add js library hashes to ensure library is from a trusted source (#7061)

Co-authored-by: Khanh Nguyen <khanhnwin@gmail.com>

* Update index.md (#7060)

* Update index.md

Modifying security policy on flutter.dev website

* Update index.md

* Update index.md

Co-authored-by: Khanh Nguyen <khanhnwin@gmail.com>

* Update text-field-material-localizations.md (#7064)

* Update layout page gallery examples (#7065)

* Fix references to gallery (#7066)

* Updating UX jobs (#7067)

* Add IXD and UXE job descriptions and remove UXR job description

* Tweaking the UXE role

* Add new UX roles to jobs index

* Updating docs: Cleanup and embedded video (#7068)

* cleanup, card name to sentence case

* added embed packages v plugins video

* moved embedded video to site alert about packages and plugins

* Fix punctuation (#7070)

I think the question mark should not be here.

* [Content Updates] Improvements for more docs (#7063)

* 📝 Update AUTHORS

* 📝 Update multiple documents

* src/get-started/test-drive/_vscode.md

* Update src/get-started/test-drive/_restart-vscode.md

* Update src/get-started/test-drive/_vscode.md

* Update src/get-started/test-drive/_vscode.md

* Update src/get-started/test-drive/_vscode.md

* Update src/get-started/test-drive/_vscode.md

Co-authored-by: Shams Zakhour (ignore Sfshaza) <44418985+sfshaza2@users.noreply.github.com>

* removed flutter writer position from jobs page (#7074)

* Add "Customizing web app initialization" page (#7069)

* move web FAQ into directory

* Move index.md to faq.md

* Add web index page

* Move web renderers page to platform-integration/web directory

* Add web initialization page

* Update sidenav

* update web/initialization page

* Update src/development/platform-integration/web/initialization.md

Co-authored-by: Parker Lougheed <parlough@gmail.com>

* Update src/development/platform-integration/web/initialization.md

Co-authored-by: Parker Lougheed <parlough@gmail.com>

* Update src/development/platform-integration/web/initialization.md

Co-authored-by: Parker Lougheed <parlough@gmail.com>

* Update src/development/platform-integration/web/initialization.md

Co-authored-by: Parker Lougheed <parlough@gmail.com>

* Update src/development/platform-integration/web/initialization.md

Co-authored-by: Parker Lougheed <parlough@gmail.com>

* Update src/development/platform-integration/web/initialization.md

Co-authored-by: Parker Lougheed <parlough@gmail.com>

* Update src/_data/sidenav.yml

* Update src/development/platform-integration/web/initialization.md

* Update src/development/platform-integration/web/initialization.md

* Update src/development/platform-integration/web/initialization.md

* Update src/development/platform-integration/web/initialization.md

* Update src/development/platform-integration/web/initialization.md

* Update src/development/platform-integration/web/initialization.md

* Update src/development/platform-integration/web/index.md

* Update src/development/platform-integration/web/initialization.md

* Update src/development/platform-integration/web/renderers.md

* Update src/development/platform-integration/web/renderers.md

* Update src/development/platform-integration/web/renderers.md

Co-authored-by: Shams Zakhour (ignore Sfshaza) <44418985+sfshaza2@users.noreply.github.com>
Co-authored-by: Parker Lougheed <parlough@gmail.com>

* Bump superstatic from 7.1.0 to 8.0.0 (#7078)

Bumps [superstatic](https://github.com/firebase/superstatic) from 7.1.0 to 8.0.0.
- [Release notes](https://github.com/firebase/superstatic/releases)
- [Commits](firebase/superstatic@v7.1.0...v8.0.0)

---
updated-dependencies:
- dependency-name: superstatic
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update submodules with excerpter binary files fix (#7075)

* Update submodules with excerpter binary files fix

* Update code excerpts

* Adjust text for changes in codelab

* Update codelab to remove repeated instructions

* Update codelabs again

* Mention stable release with lints (#7079)

* Fixes for web init PR (#7081)

Co-authored-by: John Ryan <ryjohn@google.com>

* Bump github/codeql-action from 2.1.8 to 2.1.9 (#7082)

* Update site-shared with activesupport fix (#7083)

* Update site-shared with activesupport fix

* Update site-shared submodule again

* Set default permissions to read-all in order to address code scanning alert (#7085)

* Bump firebase-tools from 10.7.1 to 10.7.2 (#7087)

Bumps [firebase-tools](https://github.com/firebase/firebase-tools) from 10.7.1 to 10.7.2.
- [Release notes](https://github.com/firebase/firebase-tools/releases)
- [Commits](firebase/firebase-tools@v10.7.1...v10.7.2)

---
updated-dependencies:
- dependency-name: firebase-tools
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Fix perf/shader image links (#7086)

* implement website freeze PR template (#7088)

Co-authored-by: Alex Li <github@alexv525.com>
Co-authored-by: godofredoc <godofredoc@google.com>
Co-authored-by: Shams Zakhour (ignore Sfshaza) <44418985+sfshaza2@users.noreply.github.com>
Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: Michael Thomsen <mit@google.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Brett Morgan <brettmorgan@google.com>
Co-authored-by: Brian Tobin <brianjtobin@gmail.com>
Co-authored-by: Hans Muller <hans.muller@gmail.com>
Co-authored-by: Jesús S Guerrero <jesus_sguerrero@hotmail.com>
Co-authored-by: drewroengoogle <102626803+drewroengoogle@users.noreply.github.com>
Co-authored-by: khyati82 <61220466+khyati82@users.noreply.github.com>
Co-authored-by: Pierre-Louis <6655696+guidezpl@users.noreply.github.com>
Co-authored-by: Tao Dong <taodong@google.com>
Co-authored-by: Shamira <23406866+MiraMarshall@users.noreply.github.com>
Co-authored-by: Filip Hracek <filiph@users.noreply.github.com>
Co-authored-by: John Ryan <ryjohn@google.com>
Co-authored-by: Parker Lougheed <parlough@gmail.com>
Co-authored-by: Ambrose Chua <ambrose@hey.com>

* Update build action for website-private repo (#12)

* update build action to run on website-private repo. Don't run deploy action.

* replace PR template

* Update iOS deployment instructions (#13)

* Update  iOS deployment instructions

* Update src/deployment/ios.md

* Update src/deployment/ios.md

Co-authored-by: Shams Zakhour (ignore Sfshaza) <44418985+sfshaza2@users.noreply.github.com>

* docker build fix for M1 (#17)

* Drop desktop beta warnings (#15)

* Update firebase.json (#16)

Adding redirect for the "Put Flutter to Work" project. This shortlink is mentioned in our PA keynote.

* Drop macOS desktop beta instructions pt 2 (#19)

* Bump firebase-tools from 10.7.2 to 10.8.0 (#20)

Bumps [firebase-tools](https://github.com/firebase/firebase-tools) from 10.7.2 to 10.8.0.
- [Release notes](https://github.com/firebase/firebase-tools/releases)
- [Commits](firebase/firebase-tools@v10.7.2...v10.8.0)

---
updated-dependencies:
- dependency-name: firebase-tools
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Add redirect for Flame DartPad (#21)

Adds a single redirect for the Flame DartPad game. This will be used in Adventure.

* Adding redirect for Put Flutter to Work (#22)

The adventure dome is using a link based on the project's old name (Take Flutter Home), so we'll this one to point to the GitHub repo as well.

* Apple silicon download button (#23)

* test change

* Update build.yml

include io22-working branch for automated builds

* Update build.yml

comment out deploy step until we update the firebase project and firebase token

* Update build.yml

change the specified repo for builds to run

* remove test line

* macos arm64 download button

* apple silicon download sdk button and instructions

* dynamically update install instructions if arm64 button clicked

* cleaned up archive.js and added comments for apple silicon download button

* switch download channel to stable (#24)

* Make examples/ pass dart analyze (#14)

* resolve errors for examples/internationalization/add_language

* fix dart analyze errors on examples/ui/layout/adaptive_app_demos

* clean up broken code excerpts + refresh excerpts

* set beta channel experimental to false, disabling continue-on-error for beta build

* set stable to experimental so that it continues on error

* Update macOS installation instructions for Rosetta and CocoaPods (#27)

* Update macOS installation instructions for Rosetta and CocoaPods

* Update src/get-started/install/_ios-setup.md

Co-authored-by: Shams Zakhour (ignore Sfshaza) <44418985+sfshaza2@users.noreply.github.com>

* Fix typo in CocoaPods installation (#28)

* Happy Paths (#18)

* assets for happy path

* styling for images

* added happy paths to side nav

* landing page

* paths info page

* link to happy paths on Flutter favorites

* updated image path and copy for landing page

* changed landing page formatting

* updated copy and formatted with semantic line breaks

* added happy paths link to Flutter favorites

* updated directory location

* updated happy paths link in flutter favorites

* addressing format comments

* unused file path

* removed Happy paths header image

* Update src/development/packages-and-plugins/happy-paths/paths/index.md

* Update src/development/packages-and-plugins/happy-paths/paths/index.md

* Update src/development/packages-and-plugins/happy-paths/paths/index.md

* Update src/development/packages-and-plugins/happy-paths/paths/index.md

* Update src/development/packages-and-plugins/happy-paths/paths/index.md

* Update src/development/packages-and-plugins/happy-paths/paths/index.md

* Update src/development/packages-and-plugins/happy-paths/paths/index.md

* Update src/development/packages-and-plugins/happy-paths/paths/index.md

* updated descriptions and links

* added cropped header and removed unnecessary styling

* updated links and edits

* updated link format

* Update src/_data/sidenav.yml

* Update src/development/packages-and-plugins/favorites.md

* Update src/development/packages-and-plugins/happy-paths/paths/index.md

* Update src/_data/sidenav.yml

* Update src/development/packages-and-plugins/favorites.md

* Update src/development/packages-and-plugins/happy-paths/paths/index.md

* Update src/development/packages-and-plugins/happy-paths/index.md

* Update src/development/packages-and-plugins/happy-paths/index.md

* Update src/development/packages-and-plugins/happy-paths/index.md

* Update src/development/packages-and-plugins/happy-paths/index.md

* Update src/development/packages-and-plugins/happy-paths/index.md

* Update src/development/packages-and-plugins/happy-paths/paths/index.md

* updated geolocation package

* sidenav build fix

* updated file names and removed header image

* Update src/development/packages-and-plugins/favorites.md

* Update src/development/packages-and-plugins/happy-paths/index.md

* Update src/development/packages-and-plugins/happy-paths/index.md

Co-authored-by: Shams Zakhour (ignore Sfshaza) <44418985+sfshaza2@users.noreply.github.com>

* Bump activesupport from 7.0.2.4 to 7.0.3 (#30)

Bumps [activesupport](https://github.com/rails/rails) from 7.0.2.4 to 7.0.3.
- [Release notes](https://github.com/rails/rails/releases)
- [Changelog](https://github.com/rails/rails/blob/v7.0.3/activesupport/CHANGELOG.md)
- [Commits](rails/rails@v7.0.2.4...v7.0.3)

---
updated-dependencies:
- dependency-name: activesupport
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update what's new page (#31)

* scaffold release notes

* create release notes

* add link to medium article

Co-authored-by: Shams Zakhour (ignore Sfshaza) <44418985+sfshaza2@users.noreply.github.com>

* Updating the codelabs page. (#29)

* Updating the codelabs page. The GDE workshops page will be live tomorrow.

* Updating link to GDE labs

* Adding the new docs games page (#33)

* remove m1 mac supplementary notes banner (#34)

* Updates to what's new for the release (#32)

* stash

* stashing

* stashing

* Updating the what's new page

* Updating what's new for the release

* Update Flutter community Dartpad link

* change codelabs submodule commit

* Update src/whats-new.md

Co-authored-by: Parker Lougheed <parlough@gmail.com>

* update codelabs submodule to resolve conflict

Co-authored-by: Khanh Nguyen <khanhnwin@gmail.com>
Co-authored-by: Parker Lougheed <parlough@gmail.com>

* Revert "remove m1 mac supplementary notes banner (#34)" (#35)

This reverts commit 9a8e25f.

* Release notes (#36)

* scaffold release notes

* create release notes

* add link to medium article

* fix release notes broken link

* Fix links in the Flutter 3 - What's new entry (#37)

* Fix links in the Flutter 3 - What's new entry

* Update wording

* Update src/whats-new.md

LOL. OK.

Co-authored-by: Parker Lougheed <parlough@gmail.com>

Co-authored-by: Shams Zakhour (ignore Sfshaza) <44418985+sfshaza2@users.noreply.github.com>

* remove dart-tool 1.19 banner (#38)

* Add missing line break to games toolkit page (#39)

* Bump github/codeql-action from 2.1.9 to 2.1.10 (#41)

Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.1.9 to 2.1.10.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@7502d6e...75b4f1c)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump firebase-tools from 10.8.0 to 10.9.0 (#42)

Bumps [firebase-tools](https://github.com/firebase/firebase-tools) from 10.8.0 to 10.9.0.
- [Release notes](https://github.com/firebase/firebase-tools/releases)
- [Commits](firebase/firebase-tools@v10.8.0...v10.9.0)

---
updated-dependencies:
- dependency-name: firebase-tools
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Remove "Useful links" TOC entries from Happy paths (#40)

* add io happening now banner (#43)

* add io happening now banner

* Update src/_includes/banner.html

Co-authored-by: Parker Lougheed <parlough@gmail.com>

Co-authored-by: Parker Lougheed <parlough@gmail.com>

* restore github build actions for public repo

* put back regular PR template

* update broken happy paths link

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Alex Li <github@alexv525.com>
Co-authored-by: godofredoc <godofredoc@google.com>
Co-authored-by: Shams Zakhour (ignore Sfshaza) <44418985+sfshaza2@users.noreply.github.com>
Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: Michael Thomsen <mit@google.com>
Co-authored-by: Brett Morgan <brettmorgan@google.com>
Co-authored-by: Brian Tobin <brianjtobin@gmail.com>
Co-authored-by: Hans Muller <hans.muller@gmail.com>
Co-authored-by: Jesús S Guerrero <jesus_sguerrero@hotmail.com>
Co-authored-by: drewroengoogle <102626803+drewroengoogle@users.noreply.github.com>
Co-authored-by: khyati82 <61220466+khyati82@users.noreply.github.com>
Co-authored-by: Pierre-Louis <6655696+guidezpl@users.noreply.github.com>
Co-authored-by: Tao Dong <taodong@google.com>
Co-authored-by: Shamira <23406866+MiraMarshall@users.noreply.github.com>
Co-authored-by: Filip Hracek <filiph@users.noreply.github.com>
Co-authored-by: John Ryan <ryjohn@google.com>
Co-authored-by: Parker Lougheed <parlough@gmail.com>
Co-authored-by: Ambrose Chua <ambrose@hey.com>
Co-authored-by: Jenn Magder <magder@google.com>
Co-authored-by: Andrew Brogdon <RedBrogdon@users.noreply.github.com>
Co-authored-by: Kevin Chisholm <kevinjchisholm@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a.tut.tutorial Relates to the Tutorial section of docs.flutter.dev
Projects
None yet
Development

No branches or pull requests

3 participants