使Flutter中的双向Scroll View加载时间更高效

时间:2019-07-15 15:32:45

标签: android flutter dart flutter-sliver

我有一个plugin,它用于滚动沿对角线或任何方向超出设备宽度和高度的窗口小部件。为了使其性能更高,我添加了条子,这些条子使非常大的网格的滚动方式更加平滑。但是,我无法缩短大型网格的加载时间。在打开带有大网格的页面时,谁能提供一些有关如何缩短加载时间的见识?

这是我正在使用的插件

bidirectional_scroll_view: "^0.1.1"

这是我正在运行的用于模拟非常大的网格的测试代码:

import 'package:flutter/material.dart';
import 'package:bidirectional_scroll_view/bidirectional_scroll_view.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  BidirectionalScrollViewPlugin _plugin;


  @override
  void initState() {
    super.initState();
    _plugin = new BidirectionalScrollViewPlugin(
      childWidth: 40.0*100,
      childHeight: 40.0*100,
      child: _buildWidgets(),
      velocityFactor: 2.0,
      scrollListener: (offset) {

      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Bidirectional ScrollView Plugin'),
        ),
        body: new Center(
            child: _plugin
        ),
      ),
    );
  }

  Widget _buildWidgets() {
    List<Widget> list = new List();

    for (int i = 0; i < 100; i++) {
      list.add(new PatternCell(
        text: i.toString(), width: 40.0, height: 40.0, onNoteSelected: () {

      },));
    }

    List<Widget> newList = new List();
    for (int i = 0; i < 100; i++) {
      newList.add(new Column(
        children: list.map((widget) {
          return widget;
        }).toList(),
      ));
    }

    return new Row(
      children: newList,
    );
  }
}

class PatternCell extends StatefulWidget {
  PatternCell({this.text, this.width, this.height, this.onNoteSelected});

  final String text;
  final double width;
  final double height;
  final VoidCallback onNoteSelected;

  @override
  State<StatefulWidget> createState() {
    return new PatternCellState();
  }
}

class PatternCellState extends State<PatternCell> {
  bool _selected = false;

  @override
  Widget build(BuildContext context) {
    Color color = Colors.transparent;
    if (_selected) {
      color = Colors.white.withOpacity(0.6);
    }

    return new InkWell(
      child: new Container(
          height: widget.height,
          width: widget.width,
          decoration: new BoxDecoration(
              border: new Border(
                top: new BorderSide(width: 0.5,
                    color: Colors.black),
                left: new BorderSide(width: 0.5,
                    color: Colors.black),
                right: new BorderSide(width: 0.5,
                    color: Colors.black),
                bottom: new BorderSide(width: 0.5,
                    color: Colors.black),
              ),
              color: color
          ),
          child: new Center(
            child: new Text(widget.text,
            ),
          )
      ),
      onTap: () {
        if (widget.onNoteSelected != null) {
          widget.onNoteSelected();
        }
      },
    );
  }
}

有人可以看看插件的实现,并告诉我在大型网格的应用程序加载时间方面可以做些改进吗?

0 个答案:

没有答案