当前位置:网站首页>Shutter nestedscrollview sliding folding head pull-down refresh effect
Shutter nestedscrollview sliding folding head pull-down refresh effect
2022-06-28 05:24:00 【Young people who get up early】
.
—— Holding a sword in the end of the world , Start with your little accumulation , Where to go , We must keep improving , Beautiful application experience From the processing of details , More from the self-demand and efforts of farmers
Flutter It's Google's latest mobile development framework .
【x1】 Daily reminder of WeChat official account At any time Accumulate... Every day I can't help it Scan the code at the bottom of the article to pay attention to
【x2】 Various series of video tutorials Free and open source Focus on You don't get lost
【x3】 Series articles One million Demo At any time Copy and paste Use
【x4】 The five minute video takes you quickly through the build
【x5】 Source code at a glance
As shown in the figure below , Yours APP The project will certainly be applied to such a scenario .

With the character of Xiaobian , To achieve a million Demo Copy and paste at any time is sure to need the source code
The complete source code is here
Next step by step to achieve , First of all, it uses a separate one dart File as a starting entry , To facilitate Demo To achieve the effect of , The definition is as follows :
// Start the function
void main() {
runApp(RootApp());
}
// root directory
class RootApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(primaryColor: Colors.grey[200]),
// Default start page
home: HomePage(),
);
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
Initialize to create a TabController Used to control TabBar And TabBarView The linkage effect of :
class HomePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _ScrollHomePageState();
}
}
class _ScrollHomePageState extends State with SingleTickerProviderStateMixin {
// Here the tag page uses TabView So you need to create a controller
TabController tabController;
// Page initialization method
@override
void initState() {
super.initState();
// initialization
tabController = new TabController(length: 3, vsync: this);
}
// Page destruction callback lifecycle
@override
void dispose() {
tabController.dispose();
}
...
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
For the body of the page Used Scaffold :
@override
Widget build(BuildContext context) {
// Build the body of the page
return Scaffold(
// The drop-down refresh
body: RefreshIndicator(
// Scrollable components send when scrolling ScrollNotification Type of notice
notificationPredicate: (ScrollNotification notifation) {
// This property contains the current ViewPort And scrolling position
ScrollMetrics scrollMetrics = notifation.metrics;
if (scrollMetrics.minScrollExtent == 0) {
return true;
} else {
return false;
}
},
// Refresh callback method
onRefresh: () async {
// Simulate network refresh wait for 2 second
await Future.delayed(Duration(milliseconds: 2000));
// Return value to end refresh
return Future.value(true);
},
child: buildNestedScrollView(),
),
);
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
RefreshIndicator It's a drop-down refresh component , Used to trigger the pull-down refresh effect , Direct nesting NestedScrollView Slide layout to use
//NestedScrollView Basic use of
Widget buildNestedScrollView() {
// Slide view
return NestedScrollView(
// Configure foldable head layout
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return [buildSliverAppBar()];
},
// The main content of the page
body: buidChildWidget(),
);
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
NestedScrollView There are two parts , Part of it is the folded head , Use SliverAppBar To achieve , The other part is the main body of the slide switch page Use TabBarView To achieve
// It's usually used PageView + BottomNavigationBar perhaps TabBarView + TabBar When
// You'll find that when you switch to another page , The previous page will be destroyed , When you go back to the previous page , The page will be rebuilt ,
// And then the data will be reloaded , Control will re render It brings a very bad user experience .
// because TabBarView It's also used internally PageView, So the solutions are the same
// The main content of the page
Widget buidChildWidget() {
return TabBarView(
controller: tabController,
children: <Widget>[
ItemPage1(1),
ItemPage1(2),
ItemPage1(3),
],
);
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
SliverAppBar The implementation is as follows :
//flexibleSpace Collapsible content area
buildSliverAppBar() {
return SliverAppBar(
title: buildHeader(),
// Center the title
centerTitle: true,
// When this value is true when SliverAppBar Will be fixed at the top of the page
// When this value is fase when SliverAppBar It's going to slide up with the slide
pinned: true,
// The duty of true when SliverAppBar Set up title Will slide up and hide
// And then configure bottom It will be shown in the original AppBar The location of
// The duty of false when SliverAppBar Set up title Will it hide
// And then configure bottom It will be shown in the original AppBar Set up title below
floating: false,
// When snap Configure to true when , Slide the page down ,SliverAppBar( And the configuration of flexibleSpace Content ) It will immediately show ,
// On the other hand when snap Configure to false when , When sliding down , Only when ListView When you slide your data to the top ,SliverAppBar It will be displayed in the dropdown .
snap: false,
elevation: 0.0,
// The height of the deployment
expandedHeight: 380,
//AppBar The content area under
flexibleSpace: FlexibleSpaceBar(
// background
// The configuration is a widget That is to say, you can use any
//Widget Combine The direct use here is a picture
background: buildFlexibleSpaceWidget(),
),
bottom: buildFlexibleTooBarWidget(),
);
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
SliverAppBar There are three parts in it , The first part is the title section , adopt title Attribute configuration , The code is as follows :
// structure SliverAppBar The title of the title
buildHeader() {
// Transparent components
return Container(
width: double.infinity,
padding: EdgeInsets.only(left: 10),
height: 38,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.white),
borderRadius: BorderRadius.circular(30),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.search_rounded,
size: 18,
),
SizedBox(
width: 4,
),
Text(
" Search for ",
style: TextStyle(
fontSize: 14,
),
),
],
),
);
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
The second part is the carousel used to fold parts , adopt flexibleSpace Property configuration FlexibleSpaceBar Middle configuration , The code is as follows :
buildFlexibleSpaceWidget() {
return Column(
children: [
Container(
height: 240,
child: BannerHomepage(isTitle: false,),
),
Container(
child: Row(
children: [
Expanded(
child: Container(
height: 120,
color: Colors.blueGrey,
child: Image.asset("images/banner5.jpeg"),
),
),
Expanded(
child: Container(
color: Colors.brown,
height: 120,
child: Image.asset("images/banner6.jpeg"),
),
),
],
),
)
],
);
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
BannerHomepage The implementation of the carousel diagram is here
The third part is through bottom Configured TabBar TAB bar , Combine it here PreferredSize To use , The code is as follows :
//[SliverAppBar] Of bottom Attribute configuration
Widget buildFlexibleTooBarWidget() {
//[PreferredSize] Used to configure in AppBar Or is it SliverAppBar
// Of bottom in Realization PreferredSizeWidget
return PreferredSize(
// Define size
preferredSize: Size(MediaQuery.of(context).size.width, 44),
// Configure any child Widget
child: Container(
alignment: Alignment.center,
child: Container(
color: Colors.grey[200],
// As you slide up ,TabBar The width of the
// Parent layout Container Constraint is center alignment
// So what Cheng shows is the middle x The effect of axis magnification
width: MediaQuery.of(context).size.width,
child: TabBar(
controller: tabController,
tabs: <Widget>[
new Tab(
text: " Tag one ",
),
new Tab(
text: " Label two ",
),
new Tab(
text: " Tag three ",
),
],
),
),
),
);
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
With the character of Xiaobian , To achieve a million Demo Copy and paste at any time is sure to need the source code
The complete source code is here

Of course, with Xiaobian's character , There must be a video recording , Click here , have interest in You can focus on Watermelon Video — Young people who get up early
边栏推荐
- When using the MessageBox of class toplevel, a problem pops up in the window.
- Learning Tai Chi Maker - mqtt Chapter 2 (V) heartbeat mechanism
- How does the power outlet transmit electricity? Simple problems that have plagued my little friend for so many years
- Concurrent wait/notify description
- Rxswift -- (1) create a project
- Unity delegate
- Share a powerful tool for factor Mining: genetic programming
- Organize the online cake mall project
- Leetcode 88: merge two ordered arrays
- The latest examination questions and answers for the eight members (standard members) of Liaoning architecture in 2022
猜你喜欢

双向电平转换电路

Extjs图书管理系统源码 智能化图书管理系统源码

Have you finished the examination of level II cost engineer? There are also qualification regulations!
![[leetcode] 12. Integer to Roman numeral](/img/3e/815f24a85a3333ce924acee1856f62.png)
[leetcode] 12. Integer to Roman numeral

Lumiprobe细胞成像分析:PKH26 细胞膜标记试剂盒

【C语言练习——打印空心正方形及其变形】

JS 文本框失去焦点修改全半角文字和符号

Learning Tai Chi Maker - mqtt Chapter II (VI) mqtt wills

Extjs library management system source code intelligent library management system source code

并发之wait/notify说明
随机推荐
【Linux】——使用xshell在Linux上安装MySQL及实现Webapp的部署
Sqlmap tool user manual
Camera Basics
Deeplearning ai-week1-quiz
PMP考试成绩多久出来?这些你务必知道!
Excel将一行的内容进行复制时,列与列之间是用制表符“\t”进行分隔的
MCLK configuration of Qualcomm platform camera
活性染料研究:Lumiprobe AF594 NHS 酯,5-异构体
TypeScript基础类型
高通平台 Camera 之 MCLK 配置
Prove that there are infinite primes / primes
How to do a good job of gateway high availability protection in the big promotion scenario
Object detection with OpenCV
Reactive dye research: lumiprobe af594 NHS ester, 5-isomer
metaRTC5.0 API编程指南(一)
【无标题】drv8825步进电机驱动板子原理图
Operation of simulated examination platform of G3 boiler water treatment recurrent training question bank in 2022
codeforces每日5题(均1700)
Store inventory management system source code
Unity out ref params