当前位置:网站首页>[shutter] monitor the transparency gradient of the scrolling action control component (remove the blank of the top status bar | frame layout component | transparency component | monitor the scrolling
[shutter] monitor the transparency gradient of the scrolling action control component (remove the blank of the top status bar | frame layout component | transparency component | monitor the scrolling
2022-07-03 02:52:00 【Programmer community】
List of articles
- Preface
- One 、 Remove the top status bar blank
- Two 、 Frame layout component
- 3、 ... and 、 Transparency component
- Four 、 Listen for rolling events
- 5、 ... and 、 Complete code example
- 6、 ... and 、 Related resources
Preface
In the last blog 【Flutter】Banner Carousel components ( flutter_swiper plug-in unit | Swiper Components ) On the basis of development ;
One 、 Remove the top status bar blank
stay Flutter Above the interface , There is a status bar by default , Display time , Electric quantity , The Internet , Signal strength and other information , The status bar is translucent ;

have access to MediaQuery The component removes the blank part of the top status bar ;
call MediaQuery.removePadding Method , The first parameter context Set to BuildContext context , The second parameter child Set to the original component ;
Code before modification :
@override Widget build(BuildContext context) {
/// Interface framework return Scaffold( /// Centering component body: Center(), ); } The modified code : In the following code removeTop: true Is the key , Represents removing the blank at the top ;
@override Widget build(BuildContext context) {
/// Interface framework return Scaffold( /// Centering component body: MediaQuery.removePadding( removeTop: true, context: context, child: Center(),), ); }Effect after removing the top blank : The above is just a brief code example , See the final example for the complete code ;

Two 、 Frame layout component
To realize the frame layout style, you need to use Stack Components , The front components are in the lower layer , The rear components are on the upper layer ;
@override Widget build(BuildContext context) {
/// Interface framework return Scaffold( /// Frame layout component , The front element is in the lower layer , The latter element is on the upper layer body: Stack( children: <Widget>[ /// Eliminate blank components at the top MediaQuery.removePadding(), /// Transparency variable component Opacity(), ], ), ); }Above settings , Implemented in the Swiper Above the component Text Components , also Text Component covered Swiper Components ;

3、 ... and 、 Transparency component
Opacity The component can control the transparency change of the component , modify opacity attribute , You can change the transparency effect of components , 0 It's completely transparent , 1 It's completely opaque ;
/// Transparency variable component Opacity( opacity: appBarAlpha, child: Container( height: 80, decoration: BoxDecoration(color: Colors.white), child: Center( child: Padding( padding: EdgeInsets.only(top: 20), child: Text(" Title transparent gradient "), ), ), ), ),Four 、 Listen for rolling events
NotificationListener Components can listen for scrolling events ;
stay onNotification Property to set the listening event , Pass in a NotificationListenerCallback Method of type , The method parameter is ScrollNotification Type of ;
Specify the component to listen to : scrollNotification.depth == 0 The depth is 0 The elements of , namely ListView When elements scroll , To trigger scrolling ;
call scrollNotification.metrics.pixels Get the scrolling distance ; The rolling distance is 0 ~ 100 Between time , Transparency component transparency from 0 ~ 1 change , If the rolling distance >= 100 , Then the transparency component is 1 , If the rolling distance is less than 0 , Then the transparency is 0 ;
Be careful : After the final setting , call setState Method , to update UI ;
Code example :
NotificationListener( // Method of monitoring scrolling onNotification: (scrollNotification){
// scrollNotification.depth == 0 The depth is 0 The elements of // namely ListView When elements scroll , To trigger scrolling if(scrollNotification is ScrollUpdateNotification && scrollNotification.depth == 0) {
// from scrollNotification Get scroll parameters print(" Rolling distance ${scrollNotification.metrics.pixels}"); // The rolling distance is 0 ~ 100 Between time // Transparency component transparency from 0 ~ 1 change // If the rolling distance >= 100 , Then the transparency component is 1 double alpha = scrollNotification.metrics.pixels / 100.0; // The treatment is less than 0 and Greater than 1 In extreme cases // If only in 0 ~ 1 Between , Don't deal with it if (alpha < 0) {
alpha = 0; } else if (alpha > 1) {
alpha = 1; } // to update UI data setState(() {
appBarAlpha = alpha; }); } }, child: ListView( children: ), ),5、 ... and 、 Complete code example
import 'package:flutter/material.dart';import 'package:flutter_swiper/flutter_swiper.dart';/// Application main interface class HomePage extends StatefulWidget {
@override _HomePageState createState() => _HomePageState();}class _HomePageState extends State<HomePage> {
List _imageUrls = [ "https://img-blog.csdnimg.cn/20210401205234582.png", "https://img-blog.csdnimg.cn/20210401205307863.png", "https://img-blog.csdnimg.cn/20210401205249606.png" ]; /// Transparency of the top-level transparency component double appBarAlpha = 0; @override Widget build(BuildContext context) {
/// Interface framework return Scaffold( /// Frame layout component , The front element is in the lower layer , The latter element is on the upper layer body: Stack( children: <Widget>[ /// Eliminate blank components at the top MediaQuery.removePadding( removeTop: true, context: context, // Use NotificationListener Components , Listen to the scrolling of the list child: NotificationListener( // Method of monitoring scrolling onNotification: (scrollNotification){
// scrollNotification.depth == 0 The depth is 0 The elements of // namely ListView When elements scroll , To trigger scrolling if(scrollNotification is ScrollUpdateNotification && scrollNotification.depth == 0) {
// from scrollNotification Get scroll parameters print(" Rolling distance ${scrollNotification.metrics.pixels}"); // The rolling distance is 0 ~ 100 Between time // Transparency component transparency from 0 ~ 1 change // If the rolling distance >= 100 , Then the transparency component is 1 double alpha = scrollNotification.metrics.pixels / 100.0; // The treatment is less than 0 and Greater than 1 In extreme cases // If only in 0 ~ 1 Between , Don't deal with it if (alpha < 0) {
alpha = 0; } else if (alpha > 1) {
alpha = 1; } // to update UI data setState(() {
appBarAlpha = alpha; }); } }, child: ListView( children: <Widget>[ Container( /// Set up Banner Shuffling figure 160 Pixels height: 160, /// This is a flutter_swiper Rotation diagram of plug-in child: Swiper( /// Number of carousels itemCount: _imageUrls.length, /// Set the rotation chart to play automatically autoplay: true, /// Carousel entry component itemBuilder: (BuildContext context, int index) {
return Image.network( /// picture URL link _imageUrls[index], /// Zoom mode fit: BoxFit.fill, ); }, /// Carousel indicator pagination: SwiperPagination(), ), ), Container( height: 800, child: ListTile( title: Text(" Title transparent gradient "), ), ), ], ), ), ), /// Transparency variable component Opacity( opacity: appBarAlpha, child: Container( height: 80, decoration: BoxDecoration(color: Colors.white), child: Center( child: Padding( padding: EdgeInsets.only(top: 20), child: Text(" Title transparent gradient "), ), ), ), ), ], ), ); }}Execution results :

6、 ... and 、 Related resources
Reference material :
- Flutter Official website : https://flutter.dev/
- Flutter Plug in download address : https://pub.dev/packages
- Flutter Developing documents : https://flutter.cn/docs ( Strongly recommend )
- official GitHub Address : https://github.com/flutter
- Flutter The Chinese community : https://flutter.cn/
- Flutter Practical tutorial : https://flutter.cn/docs/cookbook
- Flutter CodeLab : https://codelabs.flutter-io.cn/
- Dart Chinese document : https://dart.cn/
- Dart Developer website : https://api.dart.dev/
- Flutter Chinese net : https://flutterchina.club/ , http://flutter.axuer.com/docs/
- Flutter Related issues : https://flutterchina.club/faq/ ( It is recommended to watch it at the introductory stage )
- GitHub Upper Flutter Open source examples : https://download.csdn.net/download/han1202012/15989510
- Flutter Practical e-books : https://book.flutterchina.club/chapter1/
Important topics :
- Flutter Animation reference documentation : https://flutterchina.club/animations/
Blog source download :
GitHub Address : https://github.com/han1202012/flutter_app ( Keep updating with the progress of the blog , There may not be the source code of this blog )
Blog source snapshot : https://download.csdn.net/download/han1202012/21515304 ( The source code snapshot of this blog , You can find the source code of this blog )
边栏推荐
- 左值右指解释的比较好的
- I2C 子系统(一):I2C spec
- 【翻译】后台项目加入了CNCF孵化器
- I2C 子系統(四):I2C debug
- [fluent] JSON model conversion (JSON serialization tool | JSON manual serialization | writing dart model classes according to JSON | online automatic conversion of dart classes according to JSON)
- Linear rectification function relu and its variants in deep learning activation function
- random shuffle注意
- 二维格式数组格式索引下标连续问题导致 返回json 格式问题
- Source code analysis | layout file loading process
- What does "where 1=1" mean
猜你喜欢
![[shutter] banner carousel component (shutter_wiper plug-in | swiper component)](/img/a6/5c97ef3f34702b83ebf0511501d757.gif)
[shutter] banner carousel component (shutter_wiper plug-in | swiper component)

Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)

Can netstat still play like this?

I2C subsystem (II): I3C spec

I2C 子系统(一):I2C spec

Mathematical statistics -- Sampling and sampling distribution

Sous - système I2C (IV): débogage I2C

Three.js本地环境搭建

C language beginner level - pointer explanation - paoding jieniu chapter
![ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc](/img/cb/145937a27ef08050a370d5a255215a.jpg)
ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc
随机推荐
Update and return document in mongodb - update and return document in mongodb
Choose it when you decide
基于can总线的A2L文件解析(2)
Reset or clear NET MemoryStream - Reset or Clear . NET MemoryStream
Today, it's time to copy the bottom!
HW initial preparation
[C语言]给账号密码进行MD5加密
错误Invalid bound statement (not found): com.ruoyi.stock.mapper.StockDetailMapper.xxxx解决
HW-初始准备
Xiaodi notes
【翻译】后台项目加入了CNCF孵化器
Didi programmers are despised by relatives: an annual salary of 800000 is not as good as two teachers
The left value and the right finger explain better
Source code analysis | layout file loading process
Linear rectification function relu and its variants in deep learning activation function
[Fuhan 6630 encodes and stores videos, and uses RTSP server and timestamp synchronization to realize VLC viewing videos]
Use cve-2021-43893 to delete files on the domain controller
怎么将yolov5中的PANet层改为BiFPN
力扣------网格中的最小路径代价
TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制