Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement scrolling selection of numbers in Flutter

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "Flutter how to achieve scrolling selection of numbers", so the editor summarizes the following contents, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to achieve scrolling selection of numbers in Flutter" article.

Something like this:

Once you've decided on the style, start writing. As for the choice of Dialog, I use SimpleDialog. If you have requirements for details, you can customize one by yourself.

ShowDialog (context: context, barrierDismissible: true, builder: (ctx) {return SimpleDialog (title: Text), contentPadding: EdgeInsets.zero Children: [PageChoose (changeBookIdCallBack: (pageNum2) {setState () {pageNum = pageNum2) });}), Divider (height: 1,), FlatButton (child: Text ('cancel'), onPressed: () {Navigator.of (context) .pop () },), Divider (height: 1,), FlatButton (child: Text ('confirm'), onPressed: () {}) },),],);})

I set contentPadding to zero and watch it comfortably. At present, part of it has been completed, and the scrolling selection number in the middle is still missing.

Create a new file and create a StatelessWidget component. There is no need for StatefulWidget or setState. Scroll numbers I first think of the PageView component, change its scrollDirection into Axis.vertical, you can achieve up and down sliding, here I need to preview the current before and after two numbers, in the setting of PageController need to give viewportFraction value, here I gave 0.3, depending on the width and height you give the component.

Class PageChoose extends StatelessWidget {PageChoose ({this.changeBookIdCallBack}); final ValueChanged changeBookIdCallBack; final PageController pagecontroller = new PageController (viewportFraction: 0.3 ~ initialPage: 1) @ override Widget build (BuildContext context) {return Center (child: Container (alignment: Alignment.center, height: 150, width: 60, child: Stack (children: [Center (child: Container (height: 50) Decoration: BoxDecoration (border: Border (top: BorderSide (width: 0.5), bottom: BorderSide (width: 0.5)), PageView.builder (itemCount: 50, controller: pagecontroller, scrollDirection: Axis.vertical, pageSnapping: true Physics: AlwaysScrollableScrollPhysics (), itemBuilder: (ctx, index) {return Center (child: Text ('$index',style: TextStyle (fontSize: 20),)) }, onPageChanged: (int index) {changeBookIdCallBack (index);},),],) }} the above is the content of this article on "how to scroll select numbers in Flutter". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report