一統天下 flutter - widget 佈局類(可以有多個子): IndexedStack - 從多個子中選擇一個顯示
示例如下:
lib\widget\layout\indexed_stack.dart
/*
* IndexedStack - 從多個子中選擇一個顯示
*
* IndexedStack 繼承自 Stack,請先參看 stack.dart 中的說明
*/
import 'package:flutter/material.dart';
class IndexedStackDemo extends StatelessWidget {
const IndexedStackDemo({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Center(
child: Container(
width: 300,
height: 300,
color: Colors.orange,
child: IndexedStack(
/// 用於指定需要顯示的元素的索引位置
index: 1, /// 只顯示第 2 個元素
children: [
Container(
width: 200,
height: 200,
color: Colors.red,
),
Container(
width: 150,
height: 150,
color: Colors.green,
),
Container(
width: 100,
height: 100,
color: Colors.blue,
),
],
),
),
);
}
}