flutter小记(7)

今日遇到的具体问题

MaterialButton取消点击动画效果,可以设置为透明,也可以把highlightColor和splashColor跟背景色设置成一个就不再有水波纹效果啦

highlightColor: Colors.transparent,//按钮按下时的背景颜色,默认是白色
splashColor: Colors.transparent,//点击时,水波动画中水波的颜色

TextField抵住软键盘的方法

resizeToAvoidBottomInset: false, 

但是在我使用底部弹出框的控键showModalBottomSheet<int>的时候(设计的是一个点击按钮,点击出现评论,并且在最下方可以输入评论并且发布),发现该方法并没有作用,所以我用ListView包裹TextField上方的评论框,然后将评论和评论框同级,作为Column的一个child,然后用Container包裹Row再包裹住TextFiled完成功能,最后的效果就是点击评论输入框,将整个评论框往上移动直到抵住屏幕的最上方。

页面跳转升级版

因为页面是栈的结构,所以跳转页面实际上是将一个新页面push到栈中,但是当当前栈页面从栈pop出来的时候,前一个页面会显示出来,有些时候不需要再显示前一个界面,可以用Navigator.pushReplacement来切换页面。
实现页面跳转并且销毁当前界面,防止无限切换。
另外Navigator.of(context).pushAndRemoveUntil()表示删除栈里的所有页面,当然也可以指定route来选择删除该页面到现页面之间的所有页面。

 Navigator.of(context).pushAndRemoveUntil(
              MaterialPageRoute(builder: (context) => Sign_in2()),
              ModalRoute.withName('/Sign_in'));//这里事先写定了的路由,实际可以在MaterialApp中添加路由
onPressed: () {
               Navigator.pushReplacement(context,
                  MaterialPageRoute(builder: (context) {
                    return Sign_in();
                  }),);
            },
源码看懂大概就行。
/// Replace the current route of the navigator that most tightly encloses the
  /// given context by pushing the given route and then disposing the previous
  /// route once the new route has finished animating in.
  ///
  /// {@template flutter.widgets.navigator.pushReplacement}
  /// If non-null, `result` will be used as the result of the route that is
  /// removed; the future that had been returned from pushing that old route will
  /// complete with `result`. Routes such as dialogs or popup menus typically
  /// use this mechanism to return the value selected by the user to the widget
  /// that created their route. The type of `result`, if provided, must match
  /// the type argument of the class of the old route (`TO`).
  ///
  /// The new route and the route below the removed route are notified (see
  /// [Route.didPush] and [Route.didChangeNext]). If the [Navigator] has any
  /// [Navigator.observers], they will be notified as well (see
  /// [NavigatorObserver.didReplace]). The removed route is notified once the
  /// new route has finished animating (see [Route.didComplete]).
  ///
  /// Ongoing gestures within the current route are canceled when a new route is
  /// pushed.
  ///
  /// Returns a [Future] that completes to the `result` value passed to [pop]
  /// when the pushed route is popped off the navigator.
  ///
  /// The `T` type argument is the type of the return value of the new route,
  /// and `TO` is the type of the return value of the old route.
  /// {@endtemplate}
  ///
  /// {@tool snippet}
  ///
  /// Typical usage is as follows:
  ///
  /// ```dart
  /// void _completeLogin() {
  ///   Navigator.pushReplacement(
  ///       context, MaterialPageRoute(builder: (BuildContext context) => MyHomePage()));
  /// }
  /// ```
  /// {@end-tool}
  ///
  /// See also:
  ///
  ///  * [restorablePushReplacement], which pushes a replacement route that can
  ///    be restored during state restoration.
  @optionalTypeArgs
  static Future<T?> pushReplacement<T extends Object?, TO extends Object?>(BuildContext context, Route<T> newRoute, { TO? result }) {
    return Navigator.of(context).pushReplacement<T, TO>(newRoute, result: result);
  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值