juliuscanute
8/10/2019 - 9:05 AM

[Creating a ListView] #dart #flutter #listview

[Creating a ListView] #dart #flutter #listview

class T1 extends StatelessWidget {
  final T1 v1;
  
  const $1({
    Key key,
    @required this.v1,
  }) : assert( v1 != null ),
       super(key: key);
  
  @override
  Widget build(BuildContext context) {
    return Widget();
  }
}
class CategoryRoute extends StatelessWidget {
  const CategoryRoute();

  static const _categoryNames = <String>[
    'Length',
    'Area',
    'Volume',
    'Mass',
    'Time',
    'Digital Storage',
    'Energy',
    'Currency',
  ];

  static const _baseColors = <Color>[
    Colors.teal,
    Colors.orange,
    Colors.pinkAccent,
    Colors.blueAccent,
    Colors.yellow,
    Colors.greenAccent,
    Colors.purpleAccent,
    Colors.red,
  ];

  /// Makes the correct number of rows for the list view.
  ///
  /// For portrait, we construct a [ListView] from the list of category widgets.
  Widget _buildCategoryWidgets(List<Widget> categories) {
    return ListView.builder(
      itemBuilder: (BuildContext context, int index) => categories[index],
      itemCount: categories.length,
    );
  }

  @override
  Widget build(BuildContext context) {
    final categories = <Category>[];

    for (var i = 0; i < _categoryNames.length; i++) {
      categories.add(Category(
        name: _categoryNames[i],
        color: _baseColors[i],
        iconLocation: Icons.cake,
      ));
    }

    final listView = Container(
      color: _backgroundColor,
      padding: EdgeInsets.symmetric(horizontal: 8.0),
      child: _buildCategoryWidgets(categories),
    );

    final appBar = AppBar(
      elevation: 0.0,
      title: Text(
        'Unit Converter',
        style: TextStyle(
          color: Colors.black,
          fontSize: 30.0,
        ),
      ),
      centerTitle: true,
      backgroundColor: _backgroundColor,
    );

    return Scaffold(
      appBar: appBar,
      body: listView,
    );
  }
 }
class $1 extends StatelessWidget {
  const $1();
  static const _listValues1 = <String>[
    'v1',
    'v2',
    'v3',
  ];
  
  _buildP1Widgets(List<Widget> p1) {
    return ListView.builder(
          itemBuilder: (BuildContext context, int index) => p1[index],
          itemCount: p1.length,
        );
  }
  
  Widget build(BuildContext context) {
      final p1 = <T1>[];
  
      for (var i = 0; i < _listValues1.length; i++) {
        p1.add(T1(value: _listValues1[i]));
      }
      
      return Container(
                  padding: EdgeInsets.symmetric(horizontal: 8.0),
                  child: _buildP1Widgets(p1),
                 );
  }
}