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 ComboBox color HOT 1
- Create `PaneItemWidget` HOT 1
- Code Assist AI for devs building with Fluent UI in Flutter HOT 1
- Padding button HOT 1
- NavigationViewๅจ DisplayMode.autoๆจกๅผไธ่ๅๆๅญ่ฟ้ฟๆฅ้ HOT 1
- ๐ Tooltips show yellow underline if a `FluentApp` is not used HOT 2
- Support maxWidth in tooltip theme
- When using the NavigationView control, if the text in the secondary menu is too long, it will overflow due to elastic expansion and contraction๐ HOT 1
- Have you considered adding support for pagination lists?
- Have you considered adding support for pagination lists? HOT 1
- ๐ Minimal Navigation Pane causes page to load twice
- [Enhancement] Allow arbitrary width `leading` widget in `NavigationAppBar`
- ๐ Flyouts with large submenus not constraining to nested navigators
- Add a way to manipulate the TabView strip
- Implement `MenuBar` HOT 1
- Implement `RadioMenuFlyoutItem` and `ToggleMenuFlyoutItem`
- ๐ PaneItem's body is re created on Navigation
- Add a `chevronSize` parameter for the `BreadcrumbBar` widget HOT 1
- Question about widgets inside Tabs.
- Chevron Arrow in Scrollbar 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.