In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, the editor will share with you the relevant knowledge points about how to use Flutter stateful components. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look.
Stateful component
Flutter is mainly divided into stateful components StatefulWidget and stateless components StatelessWidget, before we use stateless components, do not change the content of the page, when we need to dynamically modify the content of the page, if we use stateless components, the content of the page will not be updated, then we need to use stateful components.
A stateful component is a component that inherits StatefulWidget and is called when the content changes.
SetState (() {changed content})
/ / ignore_for_file: prefer_const_constructors, prefer_collection_literals, deprecated_member_use, unused_local_variable, must_be_immutable, prefer_const_literals_to_create_immutablesimport 'package:flutter/material.dart';void main () {runApp (MyApp ());} class MyApp extends StatelessWidget {const MyApp ({Key? Key}): super (key: key); @ override Widget build (BuildContext context) {return MaterialApp (home: Scaffold (appBar: AppBar (title: const Text ('Flutter Demo'),), body: const HomeContent (), theme: ThemeData (primarySwatch: Colors.yellow,),) }} / / the stateful custom component has two classes, and what we need to return is written in the second class class HomeContent extends StatefulWidget {const HomeContent ({Key? Key}): super (key: key); @ override _ HomeContentState createState () = > _ HomeContentState ();} class _ HomeContentState extends State {int count = 0 Override Widget build (BuildContext context) {return Center (child: Column (children: [Chip (label: Text ("$count"),), ElevatedButton (onPressed: () {setState (() {count++;})) }, child: Text ("Click plus one")],),);}}
These are all the contents of the article "how to use Flutter stateful components". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.