Search
 
SCRIPT & CODE EXAMPLE
 

DART

flutter dynamic table example

class PhotosList extends StatefulWidget {
  final List photos;

  PhotosList({Key key, this.photos})
      : assert(photos != null),
        super(key: key);

  @override
  _PhotosListState createState() => _PhotosListState();
}

class _PhotosListState extends State<PhotosList> {
  @override
  Widget build(BuildContext context) {
    return bodyData();
  }

  Widget bodyData() => DataTable(
      sortColumnIndex: 1,
      sortAscending: true,
      columns: <DataColumn>[
        DataColumn(
          label: Text("Company Name"),
          onSort: (_, __) {
            setState(() {
              widget.photos.sort((a, b) => a.data["quote"]["companyName"]
                  .compareTo(b.data["quote"]["companyName"]));
            });
          },
        ),
        DataColumn(
          label: Text("Dividend Yield"),
          onSort: (_, __) {
            setState(() {
              widget.photos.sort((a, b) => a.data["stats"]["dividendYield"]
                  .compareTo(b.data["stats"]["dividendYield"]));
            });
          },
        ),
        DataColumn(
          label: Text("IEX Bid Price"),
          onSort: (_, __) {
            setState(() {
              widget.photos.sort((a, b) => a.data["quote"]["iexBidPrice"]
                  .compareTo(b.data["quote"]["iexBidPrice"]));
            });
          },
        ),
        DataColumn(
          label: Text("Latest Price"),
          onSort: (_, __) {
            setState(() {
              widget.photos.sort((a, b) => a.data["stats"]["latestPrice"]
                  .compareTo(b.data["stats"]["latestPrice"]));
            });
          },
        ),
      ],
      rows: widget.photos
          .map(
            (photo) => DataRow(
              cells: [
                DataCell(
                  Text('${photo.data["quote"]["companyName"] ?? ""}'),
                ),
                DataCell(
                  Text("Dividend Yield:"
                      '${photo.data["stats"]["dividendYield"] ?? ""}'),
                ),
                DataCell(
                  Text("Last Price:"
                      '${photo.data["quote"]["iexBidPrice"] ?? ""}'),
                ),
                DataCell(
                  Text("Last Price:"
                      '${photo.data["stats"]["latestPrice"] ?? ""}'),
                ),
              ],
            ),
          )
          .toList());
}
Comment

PREVIOUS NEXT
Code Example
Dart :: flutter sliver 
Dart :: sliver persistent tabbar 
Dart :: flutter block rotation 
Dart :: Chang height of the bottom Navigation bar in flutter 
Dart :: define offset for floatingActionButtonLocation flutter 
Dart :: dart flutter countdown timer 
Dart :: flutter image load 
Dart :: flutter download image from url 
Dart :: overflow box flutter 
Dart :: dart check runtime type 
Dart :: spacer in singlechildscrollview 
Dart :: custom marker google maps flutter 
Dart :: dart epoch to datetime 
Dart :: flutter counter app with block library 
Dart :: object dart 
Dart :: flutter custom error widget 
Dart :: if else dart example 
Dart :: flutter text in row not wrapping 
Dart :: dart function syntax 
Dart :: Example of shorthand (arrow syntax) function Dart 
Dart :: How to create maps by mentioning generic in flutter 
Dart :: flutter hot reload to multiple devices 
Dart :: how to disable float stack in flutter 
Dart :: proportion in flutter 
Dart :: i want number before % symbol in flutter 
Dart :: convert string date in Format yyyyMMddHHmmss to DateTime dart 
Swift :: swift uiview add tap gesture 
Swift :: swift continue 
Swift :: firebase nil value equals 
Swift :: swift get a rectangle centered 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =