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

随着数据量越多,越来越卡顿。并且到达一定程度页面卡死 #229

Closed
xielei0317 opened this issue Dec 25, 2019 · 14 comments
Closed

Comments

@xielei0317
Copy link

偶尔存在下拉卡顿,然后页面卡死

@xielei0317
Copy link
Author

今天已经能够100%复现了,就是返回从下一级页面返回到有pulltorefresh的页面的时候,再次下拉就会卡死,请问这个该怎么解决?

@medz
Copy link

medz commented Mar 5, 2020

+1 更新到最新版本后,android 没事,iOS 下拉卡顿。很迷。大佬肯定要说我用法问题了。我直接截图贴我用法的代码把!

image

下面是页面卡顿效果:
IMG_5970

这不是快速截屏的。而是要卡大约三四秒。

之前都是好好的,更新到 ^1.5.8 版本后就这样了。下面是我的环境信息:

image

@peng8350
Copy link
Owner

@medz 确实是用法问题,shrinkWrap这属性它会把Viewport展开到跟里面所有内容一样的大小,也就是说里面每个item没有缓存,你可以在item里dispose打个log,它是不会调用的当shrinkwrap=true,这么多item显示在一个界面肯定炸呀。你这里没必要使用shrinkWrap+NeverScroll,ListView.builder直接作为SmartRefresher's child

@peng8350
Copy link
Owner

关闭了,这个问题我在开启shrinkWrap了就可以完美重现了,我很肯定就是shrinkWrap导致卡顿。如果有出现卡顿或者数据量到达某个程度无法滑动(回退到初始位置)的问题,解决方法就是把ListView或GridView或CustomScrollView作为SmartRefresher的child。切记不要开启shrinkWrap且与SmartRefresher的child分离。

@peng8350 peng8350 pinned this issue Jun 28, 2020
@peng8350 peng8350 changed the title 下拉卡顿 随着数据量越多,越来越卡顿。并且到达一定程度页面卡死 Jun 28, 2020
@CodeGather
Copy link

关闭了,这个问题我在开启shrinkWrap了就可以完美重现了,我很肯定就是shrinkWrap导致卡顿。如果有出现卡顿或者数据量到达某个程度无法滑动(回退到初始位置)的问题,解决方法就是把ListView或GridView或CustomScrollView作为SmartRefresher的child。切记不要开启shrinkWrap且与SmartRefresher的child分离。

如果关闭了shrinkWrap,高度就没有办法自动计算了,怎么解决动态添加数据,是否有好的方案实现

@medz
Copy link

medz commented Sep 21, 2020

image
@peng8350 最近又出现了!!

我现在用法基本就是按照标准用法,将 CustomScrollView 作为 SmartRefresher 的 child!之前版本修改过然后不再卡顿。现在是即使这种标准用法也会卡顿!

@medz
Copy link

medz commented Sep 21, 2020

接上一个,这个在 Android 环境下和 iOS 测试环境下不卡顿,使用 Xcode 正式打包出来的 ipa 安装后,下拉太长会卡顿!轻轻下拉很近刚好能触发刷新的时候不卡顿。下拉很长距离才会卡顿。我测了另一个下拉刷新组件和 flutter 自带的下拉组件都不会出现这个问题!

@peng8350
Copy link
Owner

@CodeGather 你误解了吧,没说一定不能使用shrinkWrap,如果你想SmartRefresher嵌套在某个ListView的内部,你可以开启shrinkwrap(在SmartRefresher属性有shrinkWrap),事实上SmartRefresher也就是一个CustomScrollView来的。不过,说实在我很少见有下拉刷新套在ListView里面的需求。

@TENX-S
Copy link

TENX-S commented May 6, 2021

+1 更新到最新版本后,android 没事,iOS 下拉卡顿。很迷。大佬肯定要说我用法问题了。我直接截图贴我用法的代码把!

image

下面是页面卡顿效果:
IMG_5970

这不是快速截屏的。而是要卡大约三四秒。

之前都是好好的,更新到 ^1.5.8 版本后就这样了。下面是我的环境信息:

image

Hi, @medz. I'm wondering that how do you implement this tab and bottom bar ? Do you use any dependencies or plugins?
Thanks in advance!

I know this is definitely not the right place to ask this kind of question, but I can't figure out how to contact you, my apologies here.

@medz
Copy link

medz commented May 7, 2021

+1 更新到最新版本后,android 没事,iOS 下拉卡顿。很迷。大佬肯定要说我用法问题了。我直接截图贴我用法的代码把!
image
下面是页面卡顿效果:
IMG_5970
这不是快速截屏的。而是要卡大约三四秒。
之前都是好好的,更新到 ^1.5.8 版本后就这样了。下面是我的环境信息:
image

Hi, @medz. I'm wondering that how do you implement this tab and bottom bar ? Do you use any dependencies or plugins?
Thanks in advance!

I know this is definitely not the right place to ask this kind of question, but I can't figure out how to contact you, my apologies here.

Multiple Scaffold widgets can be nested. Scaffold can be nested.

@medz
Copy link

medz commented May 7, 2021

+1 更新到最新版本后,android 没事,iOS 下拉卡顿。很迷。大佬肯定要说我用法问题了。我直接截图贴我用法的代码把!
image
下面是页面卡顿效果:
IMG_5970
这不是快速截屏的。而是要卡大约三四秒。
之前都是好好的,更新到 ^1.5.8 版本后就这样了。下面是我的环境信息:
image

Hi, @medz. I'm wondering that how do you implement this tab and bottom bar ? Do you use any dependencies or plugins?
Thanks in advance!

I know this is definitely not the right place to ask this kind of question, but I can't figure out how to contact you, my apologies here.

@TENX-S Multiple Scaffold widgets can be nested. Scaffold can be nested.

@TENX-S
Copy link

TENX-S commented May 7, 2021

+1 更新到最新版本后,android 没事,iOS 下拉卡顿。很迷。大佬肯定要说我用法问题了。我直接截图贴我用法的代码把!
image
下面是页面卡顿效果:
IMG_5970
这不是快速截屏的。而是要卡大约三四秒。
之前都是好好的,更新到 ^1.5.8 版本后就这样了。下面是我的环境信息:
image

Hi, @medz. I'm wondering that how do you implement this tab and bottom bar ? Do you use any dependencies or plugins?
Thanks in advance!
I know this is definitely not the right place to ask this kind of question, but I can't figure out how to contact you, my apologies here.

@TENX-S Multiple Scaffold widgets can be nested. Scaffold can be nested.

Thank you for the reply.

I seem to understand a bit. And if it doesn't bother you too much, would you mind sending me a demo to learn some stuff like that.

Best regards!

@medz
Copy link

medz commented May 7, 2021

@TENX-S Code:

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int index = 1;
  PageController pageController;

  @override
  void initState() {
    super.initState();
    pageController = PageController(
      initialPage: index,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: pageController,
        children: [
          HomePage(),
          Explore(),
          Search(),
        ],
        physics: const NeverScrollableScrollPhysics(),
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: index,
        onTap: (int index) {
          this.setState(() {
            this.index = index;
            pageController.jumpToPage(index);
          });
        },
        items: [
          BottomNavigationBarItem(
            label: 'Home',
            icon: Icon(Icons.home)
          ),
          BottomNavigationBarItem(
            label: 'Explore',
            icon: Icon(Icons.explore)
          ),
          BottomNavigationBarItem(
            label: 'Search',
            icon: Icon(Icons.explore)
          ),
        ],
      ),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with SingleTickerProviderStateMixin {
  TabController controller;

  @override
  void initState() {
    super.initState();
    controller = TabController(initialIndex: 0, length: 3, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          title: TabBar(tabs: [
            Tab(text: 'Tab 1'),
            Tab(text: 'Tab 2'),
            Tab(text: 'Tab 2'),
          ],
          controller: controller,
          isScrollable: true
        ),
      ),
      body: TabBarView(
        controller: controller,
        children: [
          Text('Tab 1'),
          Text('Tab 2'),
          Text('Tab 3'),
        ],
      ),
    );
  }
}

class Explore extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Explore'),
      ),
    );
  }
  
}

class Search extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Text('Search');
  }
  
}

@TENX-S
Copy link

TENX-S commented May 7, 2021

@TENX-S Code:

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int index = 1;
  PageController pageController;

  @override
  void initState() {
    super.initState();
    pageController = PageController(
      initialPage: index,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: pageController,
        children: [
          HomePage(),
          Explore(),
          Search(),
        ],
        physics: const NeverScrollableScrollPhysics(),
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: index,
        onTap: (int index) {
          this.setState(() {
            this.index = index;
            pageController.jumpToPage(index);
          });
        },
        items: [
          BottomNavigationBarItem(
            label: 'Home',
            icon: Icon(Icons.home)
          ),
          BottomNavigationBarItem(
            label: 'Explore',
            icon: Icon(Icons.explore)
          ),
          BottomNavigationBarItem(
            label: 'Search',
            icon: Icon(Icons.explore)
          ),
        ],
      ),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with SingleTickerProviderStateMixin {
  TabController controller;

  @override
  void initState() {
    super.initState();
    controller = TabController(initialIndex: 0, length: 3, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          title: TabBar(tabs: [
            Tab(text: 'Tab 1'),
            Tab(text: 'Tab 2'),
            Tab(text: 'Tab 2'),
          ],
          controller: controller,
          isScrollable: true
        ),
      ),
      body: TabBarView(
        controller: controller,
        children: [
          Text('Tab 1'),
          Text('Tab 2'),
          Text('Tab 3'),
        ],
      ),
    );
  }
}

class Explore extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Explore'),
      ),
    );
  }
  
}

class Search extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Text('Search');
  }
  
}

Thanks a lot!

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

5 participants