Comments (2)
With some research, I found a workaround. Maybe it's good to incorporate to behavior of a TabView in this Lib.
Based on post from Diego Velasquez, at https://medium.com/@diegoveloper/flutter-persistent-tab-bars-a26220d322bc,
Here it goes:
import 'package:fluent_ui/fluent_ui.dart';
void main() {
runApp(const TestPage());
}
class TestPage extends StatefulWidget {
const TestPage({super.key});
@override
State<TestPage> createState() => _TestPageState();
}
class _TestPageState extends State<TestPage> {
int currentIndex = 0;
@override
Widget build(BuildContext context) {
return FluentApp(
home: TabView(
currentIndex: currentIndex,
onChanged: (value) => setState(() {
currentIndex = value;
}),
tabs: [
Tab(text: const Text('test 1'), body: const CounterPage()),
Tab(text: const Text('test 2'), body: const CounterPage()),
Tab(text: const Text('test 3'), body: const CounterPage()),
],
),
);
}
}
class CounterPage extends StatefulWidget {
const CounterPage({super.key});
@override
State<CounterPage> createState() => _CounterPageState();
}
class _CounterPageState extends State<CounterPage> with AutomaticKeepAliveClientMixin<CounterPage> {
int counter = 0;
void increment(){
setState(() {
counter++;
});
}
@override
Widget build(BuildContext context) {
return Column(children: [
Text('$counter'),
Button(onPressed: increment, child: const Text('increment'))
],);
}
@override
bool get wantKeepAlive => true;
}
just add the "AutomaticKeepAliveClientMixin" in the state of stateful widget and override the "wantKeepAlive" property to "true", boom! the magic it did.
Thanks in advance, the post from Diego Velasquez and the fluent_ui by itself is the most incredible thing that I see in flutter in the last years.
PS: I'm brazilian and my english maybe is not the best, forgive me by the prose, please.
from fluent_ui.
TabView
uses PageView
under the hood, which doesn't support the automatic usage of KeepAlive
s, like list view or sliver lists do. It is up to the developer to add it, via AutomaticKeepAliveClientMixin
, since adding it automatically including it can lead to several performance problems.
In case of usage of go_router
, one can use StatefulShellRoute
to keep the state of the routes. Another options are also available, such as page storage.
from fluent_ui.
Related Issues (20)
- Change NavigationPane Button (Hamburguer) HOT 2
- Plans for supporting Fluent 2? HOT 1
- π Menu child group shape
- π Menu child group acrylic
- π TreeView's 'There must be at least one item' assertion
- π Error when using `CommandBar.overflowBehavior` on the web HOT 2
- Replace for NavigationBody.builder HOT 1
- π `TreeViewItem` content overflow
- π The listtile widget dont center out leading or trailing widgets on mainAxis
- How to set AppBar for ScaffoldPage HOT 2
- π ProgressRing overflows its parent
- ComboBox doesn't work with enumπ HOT 1
- How to change size of `ProgressRing` ?
- ComboboxItem disabled property. HOT 1
- π Recase dependency HOT 4
- π The text selection should disappear if the text doesn't have the focus. HOT 1
- π Infobar blink on rebuild
- π HOT 7
- π Unhandled Exception: Failed assertion: line 168 pos 12: '_overlay != null': is not true. HOT 1
- Tests HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluent_ui.