Code Monkey home page Code Monkey logo

Comments (24)

zjuwjf avatar zjuwjf commented on May 12, 2024 1

Maybe
basic.dart Context.stfState
could help you.

In Context:

/// In general, we should not need this field.
  /// When we have to use this field, it means that we have encountered difficulties.
  /// This is a contradiction between presentation & logical separation, and Flutter's Widgets system.
  ///
  /// How to use ?
  /// For example, we want to use SingleTickerProviderStateMixin
  /// We should
  /// 1. Define a new ComponentState
  ///    class CustomStfState extends ComponentState<T> with SingleTickerProviderStateMixin {}
  /// 2. Override the createState method of the Component with the newly defined CustomStfState.
  ///    @override
  ///    CustomStfState createState() => CustomStfState();
  /// 3. Get the CustomStfState via context.stfState in Effect.
  ///    AnimationController controller = AnimationController(vsync: context.stfState);
  ///    context.dispatch(ActionCreator.createController(controller));
  State get stfState;

from fish-redux.

zjuwjf avatar zjuwjf commented on May 12, 2024 1

0.1.2 has been published, which includes the getter of stfState feature.

from fish-redux.

zjuwjf avatar zjuwjf commented on May 12, 2024 1
class KeepAliveWidget extends StatefulWidget {
  final Widget child;

  const KeepAliveWidget(this.child);

  @override
  State<StatefulWidget> createState() => KeepAliveState();
}

class KeepAliveState extends State<KeepAliveWidget>
    with AutomaticKeepAliveClientMixin {
  @override
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    return widget.child;
  }
}

Widget keepAliveWrapper(Widget child) {
  return KeepAliveWidget(child);
}

from fish-redux.

layou1989 avatar layou1989 commented on May 12, 2024

@zjuwjf 这个特性什么时候能放到pub上

from fish-redux.

layou1989 avatar layou1989 commented on May 12, 2024

@zjuwjf
image
我照着例子写这边报错,是什么原因呢

from fish-redux.

zjuwjf avatar zjuwjf commented on May 12, 2024

@zjuwjf
image
我照着例子写这边报错,是什么原因呢

final TickerProvider tickerProvider = ctx.stfState;
...

from fish-redux.

jkyeo avatar jkyeo commented on May 12, 2024

Same here. (type can not be assigned to ...)
image

from fish-redux.

jkyeo avatar jkyeo commented on May 12, 2024

Same here. (type can not be assigned to ...)
image

it worked as: final TickerProvider tickerProvider = ctx.stfState as CustomStfState;

from fish-redux.

Aries233 avatar Aries233 commented on May 12, 2024

Maybe
basic.dart Context.stfState
could help you.

In Context:

/// In general, we should not need this field.
  /// When we have to use this field, it means that we have encountered difficulties.
  /// This is a contradiction between presentation & logical separation, and Flutter's Widgets system.
  ///
  /// How to use ?
  /// For example, we want to use SingleTickerProviderStateMixin
  /// We should
  /// 1. Define a new ComponentState
  ///    class CustomStfState extends ComponentState<T> with SingleTickerProviderStateMixin {}
  /// 2. Override the createState method of the Component with the newly defined CustomStfState.
  ///    @override
  ///    CustomStfState createState() => CustomStfState();
  /// 3. Get the CustomStfState via context.stfState in Effect.
  ///    AnimationController controller = AnimationController(vsync: context.stfState);
  ///    context.dispatch(ActionCreator.createController(controller));
  State get stfState;

@zjuwjf
image
我照着例子写这边报错,是什么原因呢

final TickerProvider tickerProvider = ctx.stfState;
...

`
// state.dart
class IndexState extends StatefulWidget implements Cloneable {
Orders orders;

@OverRide
IndexState clone() {
return IndexState()..orders = orders;
}

@OverRide
_IndexStateState createState() => _IndexStateState();
}

class _IndexStateState extends State
with SingleTickerProviderStateMixin {
@OverRide
Widget build(BuildContext context) {
return Container();
}
}
`

// effect.dart

image
ctx.stfState 返回的类型,不是tickerProvider,而是state

from fish-redux.

zjuwjf avatar zjuwjf commented on May 12, 2024

参考说明应该是这样

component.dart

class _IndexComponentState extends ComponentState<IndexState> with SingleTickerProviderStateMixin {}

class IndexComponent extends Component<IndexState> {
	
  @override
  _IndexComponentState createState() => _IndexComponentState();
}


Effect.dart

final TickerProvider tickerProvider = ctx.stfState;

from fish-redux.

qq329401134 avatar qq329401134 commented on May 12, 2024

请问下按照如上方式做了tabcontroller 想要添加keepalive功能应该如何配置呢,我这样配置了以后会报错

image

image

@zjuwjf @jkyeo

from fish-redux.

zjuwjf avatar zjuwjf commented on May 12, 2024

如何可以, 把上下文的代码都贴下。

from fish-redux.

qq329401134 avatar qq329401134 commented on May 12, 2024

page的state
image
with SingleTickerProviderStateMixin的新state
image
page
image

effect
image
view
image
这样操作以后tabcontroller可以正常使用,然后我想加keepalive功能
于是将新state改为如下
image
运行后报错
image

@zjuwjf

from fish-redux.

jkyeo avatar jkyeo commented on May 12, 2024

page的state
image
with SingleTickerProviderStateMixin的新state
image
page
image

effect
image
view
image
这样操作以后tabcontroller可以正常使用,然后我想加keepalive功能
于是将新state改为如下
image
运行后报错
image

@zjuwjf

What’s the lifecycle that calling _init function in effect? If it is Lifecycle.build my case the problem above.

from fish-redux.

qq329401134 avatar qq329401134 commented on May 12, 2024

image
My problem is that once I add AutomaticKeepAliveClientMixin in newstate, the program doesn't work properly.
image
@zjuwjf @jkyeo

from fish-redux.

zjuwjf avatar zjuwjf commented on May 12, 2024

嗯,看了下 是 AutomaticKeepAliveClientMixin 内部实现的问题, 它覆盖了ComponentState的build方法,导致返回了null。 你可以通过在page上添加一个wraper(widget => widget) 可以达到你的需求。

from fish-redux.

qq329401134 avatar qq329401134 commented on May 12, 2024

image
image
第二个图不会操作了,能不能指点下要如何配置,网上找不到相关配置 @zjuwjf

from fish-redux.

Aries233 avatar Aries233 commented on May 12, 2024

image
image
第二个图不会操作了,能不能指点下要如何配置,网上找不到相关配置 @zjuwjf

所以 楼主,后面实现AutomaticKeepAliveClientMixin效果了吗?我使用你们的方式,依旧没有实现

from fish-redux.

zjuwjf avatar zjuwjf commented on May 12, 2024

看上去可能和fish-redux无关 flutter/flutter#28345

from fish-redux.

qq329401134 avatar qq329401134 commented on May 12, 2024

image
image
第二个图不会操作了,能不能指点下要如何配置,网上找不到相关配置 @zjuwjf

所以 楼主,后面实现AutomaticKeepAliveClientMixin效果了吗?我使用你们的方式,依旧没有实现

其实可以的,创建一个dart内容如下
class KeepAliveWidget extends StatefulWidget {
final Widget child;

const KeepAliveWidget(this.child);

@OverRide
State createState() => KeepAliveState();
}

class KeepAliveState extends State
with AutomaticKeepAliveClientMixin {
@OverRide
bool get wantKeepAlive => true;

@OverRide
Widget build(BuildContext context) {
return widget.child;
}
}

Widget keepAliveWrapper(Widget child) {
return KeepAliveWidget(child);
}
然后这样包裹,原理都一样,框架没问题
image

from fish-redux.

ywbpmf avatar ywbpmf commented on May 12, 2024

能把实现的demo开源吗?

from fish-redux.

zjuwjf avatar zjuwjf commented on May 12, 2024

#385 在fish-redux中,直接提供这些mixin。

from fish-redux.

XingXiaoWu avatar XingXiaoWu commented on May 12, 2024

image
image
第二个图不会操作了,能不能指点下要如何配置,网上找不到相关配置 @zjuwjf

所以 楼主,后面实现AutomaticKeepAliveClientMixin效果了吗?我使用你们的方式,依旧没有实现

其实可以的,创建一个dart内容如下
class KeepAliveWidget extends StatefulWidget {
final Widget child;

const KeepAliveWidget(this.child);

@OverRide
State createState() => KeepAliveState();
}

class KeepAliveState extends State
with AutomaticKeepAliveClientMixin {
@OverRide
bool get wantKeepAlive => true;

@OverRide
Widget build(BuildContext context) {
return widget.child;
}
}

Widget keepAliveWrapper(Widget child) {
return KeepAliveWidget(child);
}
然后这样包裹,原理都一样,框架没问题
image

谢谢

from fish-redux.

hipepe avatar hipepe commented on May 12, 2024

我也遇到了类似的问题
#534

from fish-redux.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.