2017-10-15 63 views
0

我使用Flutter創建了我的滾動演示應用程序的發佈版本。我不知道爲什麼我的應用程序的ListView滾動不如顫動畫廊應用程序光滑。我使用LG G5進行這項測試。爲什麼我的撲翼應用程序的listview滾動不如撲動畫廊應用程序光滑?

這裏的a link to my app's demo

編輯: 這裏是代碼。

class ListViewSample extends StatelessWidget { 
@override 
Widget build(BuildContext buidContext) { 
return new Container(
    child: new Center(
    child: new ListView(
     children: createListTiles(), 
    ), 
    ) 
); 
} 

List<Widget> createListTiles() { 
List<Widget> tiles = <Widget>[]; 
    for(int i = 0; i < 40; i++) { 
    int count = i + 1; 
    tiles.add(
    new ListTile(
     leading: new CircleAvatar(
     child: new Text("$count"), 
     backgroundColor: Colors.lightGreen[700], 
    ), 
     title: new Text("Title number $count"), 
     subtitle: new Text("This is the subtitle number $count"), 
    ) 
); 
} 
return tiles; 
} 

有人也有同樣的感受嗎?

謝謝!

+0

你是如何實現你的ListView的?你能分享一些代碼嗎? –

回答

2

您的代碼存在的問題是您使用的是常規的ListView,這不適用於包含大量項目的列表。所有這40個小部件都保存在內存中,這會導致您所遭受的極度滾動的滾動體驗。

如果您有大量或無限量的項目,則應該使用ListView.builder代替。它僅按需構建可見列表項,這使得更大的列表可以順利滾動。

這裏有一個完整的示例中,您將如何遷移列表中的助洗劑的方法:

import 'package:flutter/material.dart'; 

class ListViewSample extends StatelessWidget { 
    @override 
    Widget build(BuildContext context) { 
    return new Scaffold(
     body: new Center(
     child: new ListView.builder(
      itemCount: 200, 
      itemBuilder: (context, index) { 
      final count = index + 1; 

      return new ListTile(
       leading: new CircleAvatar(
       child: new Text("$count"), 
       backgroundColor: Colors.lightGreen[700], 
      ), 
       title: new Text("Title number $count"), 
       subtitle: new Text("This is the subtitle number $count"), 
      ); 
      }, 
     ), 
    ), 
    ); 
    } 
} 

注意,有很多的項目,在這種情況下200,但滾動仍然是黃油順利。

+0

@Liro,謝謝!我不知道這種方法。它就像撲克牌的回收站一樣。我會試試這個,然後接受你的答案,如果我有我正在尋找的平滑滾動。 –

+0

@Liro我試了你的代碼。它確實改善了滾動效果,但仍然不如android本機構建的應用程序那樣流暢。這真的是預期撲動? –

+0

您是否在調試或發佈模式下嘗試過?據我所知,調試應用程序使用JIT編譯,速度稍慢,因此是「慢速模式」橫幅。但是發佈應用程序被編譯爲本地代碼,因此它們應該至少與本機應用程序一樣流暢,如果不是更好的話。 –

相關問題