Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

[New rule] prefer-using-list-view #400

Closed
@grafovdenis

Description

@grafovdenis

Please describe what the rule should do:

It recommends to replace Column nested into SingleChildView with ListView when none of Column's special params (mainAxisAlignment, crossAxisAlignment, etc.) were used.

It's inspired by answer of "What is the difference between ListView and SingleChildScrollView in Flutter?" question:

You could consider ListView as an optimisation to the combination of SingleChildScrollView + Column.
By using ListView, only the items that are visible are mounted and painted.
On the other hand, by using SingleChildScrollView+Column, the entire item list is mounted+painted, even if only a few items are visible.
The tradeoff is that ListView is less flexible. So for complex layouts with a small number of items, the performance gain may not be worth the trouble, in which case we can use SingleChildScrollView.

https://stackoverflow.com/a/62147092

What category of rule is this? (place an "X" next to just one item)

[ ] Warns about a potential error (problem)
[X] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about (it will be better if you can provide both good and bad examples):

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SingleChildScrollView( // Lint
          child: Column(children: [
            Text('Wow another lint rule'),
            Text('Wow another lint rule'),
          ]),
        ),
      ),
    );
  }
}

Are you willing to submit a pull request to implement this rule?
You can DM me for more details.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions