Closed b14cknc0d3 closed 3 years ago
Hi! Correct me if I got it wrong ok?
I believe that in your case, you need to keep your data in the State class. When changing tabs, Flutter reconstructs the screen because the old tab content is removed from the tree. At this moment, the data may disappear.
This is an example with a text field. If you don't keep the field controller, the typed text is lost:
import 'package:flutter/material.dart';
import 'package:tabbed_view/tabbed_view.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyPage(),
);
}
}
class MyPage extends StatefulWidget {
@override
MyPageState createState() => MyPageState();
}
class MyPageState extends State<MyPage> {
late TabbedViewController _tabbedViewController;
Map<int, TextEditingController> _fieldControllers =
Map<int, TextEditingController>();
@override
void initState() {
List<TabData> tabs = [];
for (var i = 1; i < 5; i++) {
_fieldControllers[i] = TextEditingController();
TextField field = TextField(
controller: _fieldControllers[i],
decoration: InputDecoration(border: OutlineInputBorder()),
);
tabs.add(TabData(text: 'Tab $i', content: field));
}
_tabbedViewController = TabbedViewController(tabs);
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(body: TabbedView(controller: _tabbedViewController));
}
}
Is this your problem with ApiPagedata?
I can analyze the cost of implementing AutomaticKeepAliveClientMixin in TabbedView as well.
I'm thinking of providing a solution similar to Flutter's AutomaticKeepAliveClientMixin
.
Perhaps it could also allow storing data directly in the TabData
class.
The solution will be the keepAlive
parameter in the TabData
class to keep the tab widget always in memory.
It is possible to manage sensitive data by storing them in the value
of the TabData
class.
Done. Available in version 1.2.0.
sorry for late reply .i fixed using AutomaticKeepAliveClientMixin,
I have a page call DataPage which is a stateful widget I added ApiPageData to TabData
I populated three API pages (have multiple forms) in initState.
my
tabbedView
example apipagedata