We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Now, when some child is not loaded, it would be replaced by an empty container, but it will cause It size fit parent.
For Example:
import 'package:flutter/material.dart'; import './lazy_indexed_stack.dart'; class TabView extends StatefulWidget { int index; TabView({Key key, this.index}) : super(key: key); @override _TabViewState createState() => _TabViewState(); } class _TabViewState extends State<TabView> { @override void initState() { super.initState(); print('init tabView ${widget.index}'); } @override void dispose() { super.dispose(); print('dispose tabView ${widget.index}'); } @override Widget build(BuildContext context) { print('build tabView ${widget.index}'); return Container( width: 200, height: 200, color: Colors.lightGreenAccent, child: Center( child: Text('view ${widget.index}'), ), ); } } class TestLazyIndexedStack extends StatefulWidget { TestLazyIndexedStack({Key key}) : super(key: key); @override _TestLazyIndexedStackState createState() => _TestLazyIndexedStackState(); } class _TestLazyIndexedStackState extends State<TestLazyIndexedStack> { int viewIndex = 0; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('测试 IndexedStack'), ), body: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( color: Colors.lightBlueAccent, child: LazyIndexedStack( index: viewIndex, itemCount: 3, itemBuilder: (context, index) { return TabView(index: index); }, ), ), Row( mainAxisAlignment: MainAxisAlignment.center, children: List<Widget>.generate( 3, (index) => FlatButton( onPressed: () { setState(() { viewIndex = index; }); }, child: Text('$index'), ), ), ) ], ), ); } }
result in:
When replace Container with SizedBox:
@override void initState() { _loaded = []; _children = []; for (int i = 0; i < widget.itemCount; ++i) { if (i == widget.index) { _children.add(widget.itemBuilder(context, i)); _loaded.add(true); } else { _children.add(const SizedBox()); _loaded.add(false); } } super.initState(); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Now, when some child is not loaded, it would be replaced by an empty container, but it will cause It size fit parent.
For Example:
result in:
When replace Container with SizedBox:
The text was updated successfully, but these errors were encountered: