Comments (11)
This seems like an issue with your UI code rather than the library. Where are you using the clean architecture? Perhaps share some code.
from flutter_clean_architecture.
Sure, this is my code, the page use on TabBarView
class TheFirstPage extends View {
final dynamic data;
TheFirstPage({Key key, @required this.data}) : super(key: key);
@override
State<StatefulWidget> createState() => _TheFirstPageView(data);
}
// error
class _TheFirstPageView extends ViewState<TheFirstPage, TheFirstController>
with AutomaticKeepAliveClientMixin<TheFirstPage> {
_TheFirstPageView(dynamic data)
: super(TheFirstController(SomeRepository(), data));
@override
bool get wantKeepAlive => true;
@override
void initState() {
super.initState();
print('_TheFirstPageView initState');
}
@override
Widget build(BuildContext context) {
print('_TheFirstPageView build');
super.build(context);
return super.build(context);
}
@override
Widget buildPage() {
print('_TheFirstPageView buildPage');
return Scaffold(
body: Container(...)
);
}
}
// normally work
class _TheFirstPageState extends State<ChallengeDetailsPage>
with AutomaticKeepAliveClientMixin<ChallengeDetailsPage> {
@override
void initState() {
super.initState();
print('_TheFirstPageState initState');
}
@override
Widget build(BuildContext context) {
print('_TheFirstPageState build');
super.build(context);
return Scaffold(
body: Container()
);
}
@override
bool get wantKeepAlive => true;
}
from flutter_clean_architecture.
You're actually supposed to be using buildPage()
instead of build()
inside your ViewState as stated in the documentation. So just replace it and it should work. The library marks the build()
function as nonvirtual, that means you should not be overriding it because it is used internally.
Do not override build()
and use buildPage()
for your UI such as
@override
Widget buildPage() {
print('_TheFirstPageState build');
return Scaffold(
body: Container()
);
If you still have problem after this please let me know. Try this
class _TheFirstPageView extends ViewState<TheFirstPage, TheFirstController>
with AutomaticKeepAliveClientMixin<TheFirstPage> {
_TheFirstPageView(dynamic data)
: super(TheFirstController(SomeRepository(), data));
@override
bool get wantKeepAlive => true;
@override
void initState() {
super.initState();
print('_TheFirstPageView initState');
}
@override
Widget buildPage() {
print('_TheFirstPageView buildPage');
return Scaffold(
body: Container()
);
}
}
from flutter_clean_architecture.
i try it but it show the same
i check on view.dart it actually wont call the super.build(context) like this sample https://github.com/diegoveloper/flutter-samples/blob/aa43501a8ee8799024a3422e39842329d20482c5/lib/persistent_tabbar/page2.dart
@override
@nonVirtual
Widget build(BuildContext context) {
return ChangeNotifierProvider<Con>.value(
value: _controller,
child: Consumer<Con>(builder: (ctx, con, _) {
_controller = con;
return buildPage();
}));
}
from flutter_clean_architecture.
What happens if you add
@override
Widget build(BuildContext context) {
return super.build(context);
}
Can you check if either build or buildPage gets called? If that doesn't help, I can try to recreate the issue in a small application and see what is causing the issue.
from flutter_clean_architecture.
I try to call super.build(context) on the build function of the Class that extends ViewState but it not work.
from flutter_clean_architecture.
Okay, I will make a small app and test this on my end.
from flutter_clean_architecture.
Any news, are you getting an error like me?
from flutter_clean_architecture.
I am looking into it as we speak. Will get back to you shortly.
from flutter_clean_architecture.
@tunt-04098,
I was able to replicate the issue on my end. I am reluctant to call this a bug, as this is an unfortunate side effect of how Dart
works.
Mixins
create interfaces on top of the base class. That means, if you were to extend a class with a method called foo()
and mixin with a class that also has a method called foo()
, only the Mixin's foo()
method will be recognized, as the mixin becomes the proper super class of the child class.
Since both ViewState
and AutomaticKeepAliveClientMixin
override build()
, only AutomaticKeepAliveClientMixin
's build method is called, which means the library method won't be called and won't end up building your UI. That is the cause of the issue.
What that means for me, is that I will probably have to change the method name and replace it with a widget that users can use to wrap their widgets in their build method. Either that, or people would have to use the workaround below. While I eventually decide which route I am going to take, that is, either leave it for the user to work around it or modify the library in a less user-friendly way, you can go ahead and use the workaround below:
class TheFirstPage extends View {
final dynamic data;
TheFirstPage({Key key, @required this.data}) : super(key: key);
@override
State<StatefulWidget> createState() => _TheFirstPageView(data);
}
class _TheFirstPageViewRename extends ViewState<TheFirstPage, TheFirstController> {
_TheFirstPageViewRename(controller) : super(controller);
Widget buildRename(context) => super.build(context);
@override
Widget buildPage() => null;
}
class _TheFirstPageView extends _TheFirstPageViewRename
with AutomaticKeepAliveClientMixin<TheFirstPage> {
_TheFirstPageView(dynamic data)
: super(TheFirstController(SomeRepository(), data));
@override
bool get wantKeepAlive => true;
@override
void initState() {
super.initState();
print('_TheFirstPageView initState');
}
@override
Widget build(BuildContext context) {
print('_TheFirstPageView build');
super.build(context);
return super.buildRename(context);
}
@override
Widget buildPage() {
print('_TheFirstPageView buildPage');
return Scaffold(
body: Container()
);
}
}
This simply renames the method so Flutter can differentiate between the 2. Specifically here:
class _TheFirstPageViewRename extends ViewState<TheFirstPage, TheFirstController> {
_TheFirstPageViewRename(controller) : super(controller);
Widget buildRename(context) => super.build(context);
@override
Widget buildPage() => null;
}
It's only a few added lines of code, yet it is still sub-optimal.
Let me know if you have any questions.
Thank you and happy coding!
from flutter_clean_architecture.
Thank you for your help wish you many good things!
from flutter_clean_architecture.
Related Issues (20)
- Cant add AppBar via ControlledWidgetBuilder.builder HOT 2
- One Controller for multiple pages HOT 1
- RefreshUI and setState HOT 1
- Question: Same controller in multiple widgets HOT 9
- Error when migrating from flutter_clean_architecture ^3.0.2 to ^5.0.0 HOT 1
- [Question] About initViewState() migration HOT 1
- [Question] How do I write test for the controller or presenter class? HOT 5
- If try add block isolate I have error HOT 1
- refreshUI() doesn't work with Shared Controller. HOT 1
- Can u update to support flutter_bloc >=7.2.0 HOT 2
- Unable to override `initState` on ViewState HOT 3
- How to avoid rebuild in components.
- Migrate to support 2.10.3 HOT 1
- Update to flutter 3.0 HOT 4
- integrating with Riverpod HOT 2
- I tried to make a 100% test coverage in example app but stuck in 98.3 HOT 1
- Getting this issues while app is build on ios ?
- Getting this error on ios build ?
- Add support to Dart 3 HOT 1
- Error: 'View' is imported from both
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 flutter_clean_architecture.