当前位置:网站首页>flutter系列之:flutter中的IndexedStack
flutter系列之:flutter中的IndexedStack
2022-06-21 20:33:00 【InfoQ】
简介
IndexedStack简介
class IndexedStack extends Stack
IndexedStack({
Key? key,
AlignmentGeometry alignment = AlignmentDirectional.topStart,
TextDirection? textDirection,
StackFit sizing = StackFit.loose,
this.index = 0,
List<Widget> children = const <Widget>[],
}) : super(key: key, alignment: alignment, textDirection: textDirection, fit: sizing, children: children);
@override
RenderIndexedStack createRenderObject(BuildContext context) {
assert(_debugCheckHasDirectionality(context));
return RenderIndexedStack(
index: index,
alignment: alignment,
textDirection: textDirection ?? Directionality.maybeOf(context),
);
}
@override
void updateRenderObject(BuildContext context, RenderIndexedStack renderObject) {
assert(_debugCheckHasDirectionality(context));
renderObject
..index = index
..alignment = alignment
..textDirection = textDirection ?? Directionality.maybeOf(context);
}
class RenderIndexedStack extends RenderStack
@override
void paintStack(PaintingContext context, Offset offset) {
if (firstChild == null || index == null)
return;
final RenderBox child = _childAtIndex();
final StackParentData childParentData = child.parentData! as StackParentData;
context.paintChild(child, childParentData.offset + offset);
}
IndexedStack的使用
IndexedStack(
index: _counter,
children: [
widgetOne(),
widgetTwo(),
widgetThree(),
widgetFour(),
],
)
Widget widgetOne() {
return SizedBox(
width: 100,
height: 100,
child: Container(
color: Colors.yellow,
),
);
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _changeIndex() {
setState(() {
_counter = (_counter+1) % 4;
print(_counter);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: IndexedStack(
index: _counter,
children: [
widgetOne(),
widgetTwo(),
widgetThree(),
widgetFour(),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _changeIndex,
tooltip: 'change index',
child: const Icon(Icons.arrow_back),
),
);
}

总结
边栏推荐
猜你喜欢

【深入理解TcaplusDB技术】一键安装Tmonitor后台

IP guard printing control to prevent information disclosure of printing channels

Jeu de boutons de force 4 (version MySQL)

技术分享 | MySQL中一个聚类增量统计 SQL 的需求

Enzo high sensitivity detection Arg8 vasopressin ELISA Kit

棋牌类游戏

HiC-Pro | HiC数据处理工具

从-1开始实现一个中间件

How C # aboutbox displays its defined interface

Characteristics and experimental suggestions of abbkine cell cycle Staining Kit
随机推荐
精彩回顾丨一图了解华为云专场干货
基于OpenCVSharp的001新建工程项目
[deeply understand tcapulusdb technology] tmonitor background one click installation
C# AboutBox怎么显示自己定义的界面
Use the while loop to calculate the odd and even sums in 1-100 [method 2]
利用for循环,分别计算1-100中奇数的和、偶数的和【方法一】
力扣:零钱兑换
Notes on question brushing (17) -- binary search tree: about attribute problems
【深入理解TcaplusDB技術】TcaplusDB構造數據
刷题笔记(十七)--二叉搜索树:关于属性问题
Lifting method (I) AdaBoost
【深入理解TcaplusDB技术】Tmonitor后台一键安装
软件架构介绍
C#的DataGridView中字体大小
利用while循环,分别计算1-100中奇数的和、偶数的和【方法二】
利用do while循环,分别计算1-100中奇数的和、偶数的和【方法一】
[in depth understanding of tcapulusdb technology] tcapulusdb construction data
从-1开始实现一个中间件
Dotter| dot method sequence pairwise comparison software
Contact five heart matchmaker to take off the order