Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3的easy refresh在使用Cupertino样式时,初始化刷新失效 #586

Closed
kidozh opened this issue Aug 6, 2022 · 9 comments
Closed

Comments

@kidozh
Copy link

kidozh commented Aug 6, 2022

RT,当我的界面使用了Cupertino的时候,无法初始化刷新,并且有一个很奇怪的placeholder,如下图所示
image
当然也可以手动下滑刷新出页面,但是每个页面都需要手动下拉刷新,就很麻烦。

但是使用material界面的时候,初始化刷新又是正常的:
image

这个很迷惑,我也不知道是什么原因。

@xuelongqy
Copy link
Owner

不清楚你的具体问题是什么,也许参考示例可以帮助你,并找到问题

@kidozh
Copy link
Author

kidozh commented Aug 7, 2022

就是在使用Cupertino样式https://docs.flutter.dev/development/ui/widgets/cupertino下使用EasyRefresh并开启refreshOnStart: true,时,无法在开启的时候自动刷新,而是出现上面的BUG。

@xuelongqy
Copy link
Owner

就是在使用Cupertino样式https://docs.flutter.dev/development/ui/widgets/cupertino下使用EasyRefresh并开启`refreshOnStart: true`,时,无法在开启的时候自动刷新,而是出现上面的BUG。

我测试没有问题嘞,能给一个简单的示例吗?

@kidozh
Copy link
Author

kidozh commented Aug 7, 2022

请参考这个

import 'dart:io';

import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return const CupertinoApp(
      title: 'Flutter Demo',
      theme: CupertinoThemeData(
          // This is the theme of your application.
          //
          // Try running your application with "flutter run". You'll see the
          // application has a blue toolbar. Then, without quitting the app, try
          // changing the primarySwatch below to Colors.green and then invoke
          // "hot reload" (press "r" in the console where you ran "flutter run",
          // or simply save your changes to "hot reload" in a Flutter IDE).
          // Notice that the counter didn't reset back to zero; the application
          // is not restarted.
          //primarySwatch: Colors.blue,
          ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;
  EasyRefreshController _controller = EasyRefreshController(controlFinishRefresh: true, controlFinishLoad: true);

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return CupertinoPageScaffold(
      navigationBar: const CupertinoNavigationBar(
        middle: const Text("DEMO"),
      ),
      child: EasyRefresh(
        header: ClassicHeader(),
        footer: ClassicFooter(),
        refreshOnStart: true,
        controller: _controller,
        onLoad: () async{
          //sleep(Duration(seconds: 5));
          setState((){
            _counter += 10;
          });
          _controller.finishLoad(IndicatorResult.success);
          return IndicatorResult.success;
        },
        onRefresh: () async{
          //sleep(Duration(seconds: 5));
          setState((){
            _counter = 10;
          });

          _controller.finishRefresh(IndicatorResult.success);
          return IndicatorResult.success;

        },
        child: ListView.builder(
          itemBuilder: (context, index) {
            return Card(
              child: Text((index + 1).toString()),
            );
          },
          itemCount: _counter,
        ),
      ),
      // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

@kidozh
Copy link
Author

kidozh commented Aug 7, 2022

这个刚开始就不会刷新界面,界面是这样的

image

可以隐隐约约看到后台有一个东西在刷新,但是如果用户不自己去下拉刷新,easyrefresh似乎是不会在开始打开界面的时候刷新数据的。

@xuelongqy
Copy link
Owner

我看了示例代码。这是安全区域的问题,在EasyRefresh外层加一个SafeArea即可。不过首次刷新确实有点问题,没有计算出正确的安全区域偏移量,这个会在下个版本修复

@kidozh
Copy link
Author

kidozh commented Aug 8, 2022

感谢,那我等修复吧,我懒得改了,感谢作者

@kidozh kidozh closed this as completed Aug 8, 2022
@xuelongqy
Copy link
Owner

3.0.4+2应该可以了,不过还是建议你加上SafeArea

@kidozh
Copy link
Author

kidozh commented Aug 9, 2022

好滴,感谢,我去更新一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants