flutter DataTable数据表格

摘要:
数据表显示原始数据集。它们通常出现在桌面企业产品中。DataTableWidget实现这个组件文档:https://api.flutter.dev/flutter/material/DataTable-class.htmlimport'package:flutter/material.dart';import'./model/post.dart';classDataTableDemoextendsStatefulWidget{@override_DataTableDemoStatecreateState()=˃_DataTableDemoState();}class_DataTableDemoStateextendsState{int_sortColumnIndex;bool_sortAscending=true;@overrideWidgetbuild{returnScaffold(appBar:AppBar(title:Text('DataTableDemo'),elevation:0.0,),body:Container(padding:EdgeInsets.all(16.0),child:ListView(children:[DataTable(sortColumnIndex:_sortColumnIndex,sortAscending:_sortAscending,//onSelectAll:(boolvalue){},columns:[DataColumn(label:Text('Title'),onSort:(intindex,boolascending){setState((){_sortColumnIndex=index;_sortAscending=ascending;posts.sort((a,b){if(!

数据表显示原始数据集。它们通常出现在桌面企业产品中。DataTable Widget实现这个组件

文档:https://api.flutter.dev/flutter/material/DataTable-class.html

import 'package:flutter/material.dart';
import './model/post.dart';
class DataTableDemo extendsStatefulWidget {
  @override
  _DataTableDemoState createState() =>_DataTableDemoState();
}
class _DataTableDemoState extends State<DataTableDemo>{
  int_sortColumnIndex;
  bool _sortAscending = true;
  @override
  Widget build(BuildContext context) {
    returnScaffold(
      appBar: AppBar(
        title: Text('DataTableDemo'),
        elevation: 0.0,
      ),
      body: Container(
        padding: EdgeInsets.all(16.0),
        child: ListView(
          children: <Widget>[
            DataTable(
              sortColumnIndex: _sortColumnIndex,
              sortAscending: _sortAscending,
              //onSelectAll: (bool value) {},
columns: [
                DataColumn(
                  label: Text('Title'),
                  onSort: (intindex, bool ascending) {
                    setState(() {
                      _sortColumnIndex =index;
                      _sortAscending =ascending;
                      posts.sort((a, b) {
                        if (!ascending) {
                          final c =a;
                          a =b;
                          b =c;
                        }
                        returna.title.length.compareTo(b.title.length);
                      });
                    });
                  },
                ),
                DataColumn(
                  label: Text('Author'),
                ),
                DataColumn(
                  label: Text('Image'),
                ),
              ],
              rows: posts.map((post) {
                returnDataRow(
                  selected: post.selected,
                  onSelectChanged: (bool value) {
                    setState(() {
                      if (post.selected !=value) {
                        post.selected =value;
                      }
                    });
                  },
                  cells: [
                    DataCell(Text(post.title)),
                    DataCell(Text(post.author)),
                    DataCell(Image.network(post.imageUrl)),
                  ]
                );
              }).toList(),
            ),
          ],
        ),
      )
    );
  }
}

效果:

flutter DataTable数据表格第1张


分页demo

import 'package:flutter/material.dart';
import './model/post.dart';
class PostDataSource extendsDataTableSource {
  final List<Post> _posts =posts;
  int _selectedCount = 0;
  @override
  int get rowCount =>_posts.length;
  @override
  bool get isRowCountApproximate => false;
  @override
  int get selectedRowCount =>_selectedCount;
  @override
  DataRow getRow(intindex) {
    final Post post =_posts[index];
    returnDataRow.byIndex(
      index: index,
      cells: <DataCell>[
        DataCell(Text(post.title)),
        DataCell(Text(post.author)),
        DataCell(Image.network(post.imageUrl)),
      ],
    );
  }
  void_sort(getField(post), bool ascending) {
    _posts.sort((a, b) {
      if (!ascending) {
        final c =a;
        a =b;
        b =c;
      }
      final aValue =getField(a);
      final bValue =getField(b);
      returnComparable.compare(aValue, bValue);
    });
    notifyListeners();
  }
}
class PaginatedDataTableDemo extendsStatefulWidget {
  @override
  _PaginatedDataTableDemoState createState() =>_PaginatedDataTableDemoState();
}
class _PaginatedDataTableDemoState extends State<PaginatedDataTableDemo>{
  int_sortColumnIndex;
  bool _sortAscending = true;
  final PostDataSource _postsDataSource =PostDataSource();
  @override
  Widget build(BuildContext context) {
    returnScaffold(
        appBar: AppBar(
          title: Text('PaginatedDataTableDemo'),
          elevation: 0.0,
        ),
        body: Container(
          padding: EdgeInsets.all(16.0),
          child: ListView(
            children: <Widget>[
              PaginatedDataTable(
                header: Text('Posts'),
                rowsPerPage: 5,
                source: _postsDataSource,
                sortColumnIndex: _sortColumnIndex,
                sortAscending: _sortAscending,
                //onSelectAll: (bool value) {},
columns: [
                  DataColumn(
                    label: Text('Title'),
                    onSort: (intcolumnIndex, bool ascending) {
                      _postsDataSource._sort((post) =>post.title.length, ascending);
                      setState(() {
                        _sortColumnIndex =columnIndex;
                        _sortAscending =ascending;
                      });
                    },
                  ),
                  DataColumn(
                    label: Text('Author'),
                  ),
                  DataColumn(
                    label: Text('Image'),
                  ),
                ],
              ),
            ],
          ),
        ));
  }
}

效果:

flutter DataTable数据表格第2张

免责声明:文章转载自《flutter DataTable数据表格》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇mstsc远程登录“您的凭据不工作”解决办法STM32 MCO时钟输出配置实验下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

SqlServer数据库存入decimal类型数据注意事项

对sqlserver而言,Decimal可用来保存具有小数点而且数值确定的数值,它不像float和real是用来保存近似值。目的是满足进行精密数学运算的需求,它是范围最大、最精确的浮点数类型。 decimal类型需要注意是要指定精度否则decimal就会和int一样只能存入整数。例如:decimal(18,2)就是存入长度18位,小数点后2位的数据。...

用navicate 连接本地数据库提示用户名/口令无效

1、在用navicate连接本地的oracle数据库时,试了oracle几个默认的用户名和密码,但是当我输入时,却提示用户名/口令无效。所以按照网上的办法,cmd,输入了以下命令,修改了几个用户的用户密码。 再次用admin连接即可 2、文件--新建--用户,建立admin用户 3、在新建的表里插入数据时,提示:对表空间‘USERS’无权限。 解决办法...

全基因组测序及数据分析基础

华大的春季培训课程之一:https://ke.qq.com/course/1128997?taid=7160092735650341,我认为讲得很好,介绍全面而详细,加了一些个人经验(侵删)。 流程众多,对于结果会有一些差异,尤其是对低频变异。如果很关注低频位点,可多种几款流程比较。 实际上SV结果中会包含CNV,但往往会把CNV单独拿出来...

保证看完就会!大数据YARN核心知识点来袭!

01 我们一起学大数据 大家好,今天分享的是大数据YARN的核心知识点,老刘尽量用通俗易懂的话来讲述YARN知识点,争取做到大家看完后能够用口语化的形式将它们表达出来,做到真正的看完就会!(如果觉得老刘写的不错,给老刘点个赞) 02 YARN核心知识点 第1点:什么是YARN? YARN是Hadoop架构中的资源调度引擎模块,从这个模块名字就可以看出来,...

数据仓库项目中的数据建模和ETL日志体系

数据仓库项目跨功能需求开发不够完善,导致的各种问题,就我个人经验来说,主要体现在数据建模不够标准和 ETL 日志体系不够完善两个方面,本文会详细介绍一下,如何从跨功能需求的角度,构建标准的数据建模和完善的 ETL 日志体系。   对于一个软件来说,分为功能需求和跨功能需求(Cross-Functional Requirements, CFR)。功能需求,一...

Google准实时数据仓库Mesa(一)

本文来自网易云社区 作者:王潘安 以下是本人在学习Google的Mesa数据仓库论文的记录,翻译出来给大家分享,翻译水平有限,请多多包涵。因论文比较长,本人将论文按照Mesa不同的模块分开翻译,方便阅读。 摘要:Mesa是一个可伸缩性的分析型数据仓库系统,它主要为Google的互联网广告业务服务。Mesa的设计是为了满足一系列的来自用户和系统的复杂的挑...