Flutter 飞涨的cpu速度&;仅在iOS emulator中的Syncfusion DataGrid屏幕上使用-颤振

Flutter 飞涨的cpu速度&;仅在iOS emulator中的Syncfusion DataGrid屏幕上使用-颤振,flutter,datagrid,cpu-usage,syncfusion,Flutter,Datagrid,Cpu Usage,Syncfusion,在这里寻求帮助或想法。可能是我做错了什么,也可能是有人有了可以帮助的想法 我终于找到并成功实现了两个独立的Syncfusion数据网格。它们工作完美,完全满足我的需求,尽管与DataTable相比,它们的工作方式非常复杂。对不起,我必须把那个插头插进去。无论如何,我已经在屏幕上加载了datagrid。当我进入该屏幕时,datagrid显示,我的cpu温度和风扇速度极快(每2秒一摄氏度),直到85度以上,我停止模拟器或导航到另一个屏幕。这两种操作几乎都会立即降低导航或停止后的cpu温度。这就像时钟

在这里寻求帮助或想法。可能是我做错了什么,也可能是有人有了可以帮助的想法

我终于找到并成功实现了两个独立的Syncfusion数据网格。它们工作完美,完全满足我的需求,尽管与DataTable相比,它们的工作方式非常复杂。对不起,我必须把那个插头插进去。无论如何,我已经在屏幕上加载了datagrid。当我进入该屏幕时,datagrid显示,我的cpu温度和风扇速度极快(每2秒一摄氏度),直到85度以上,我停止模拟器或导航到另一个屏幕。这两种操作几乎都会立即降低导航或停止后的cpu温度。这就像时钟工作,导航到datagrid屏幕-温度上升,导航离开-温度下降

罪魁祸首似乎是activity monitor(macbook pro)建议的“跑步者”,它开始使用75%以上的cpu

有人有什么有用的建议吗?我不知道该尝试什么,没有输出或错误。此外,datagrid中几乎没有数据。我说的是4行5格的超简单数据。。。没有理由这样。数据量为50倍的DataTable甚至没有阻塞cpu

还有一个问题,其他人对Syncfusion DataGrid有这个问题吗

编辑:使用Android Studio或VS代码启动时出现相同问题

编辑II:在物理iphone上运行不会产生相同的问题

我的DataGrid代码:

//
///
/// Income data grid- Syncfusion version
import 'package:flutter/material.dart';
import 'package:fp_provider_demo_one/models/income/income.dart';
import 'package:fp_provider_demo_one/models/income/income_data.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:syncfusion_flutter_datagrid/datagrid.dart';

class IncomeDataGrid extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Consumer<IncomeData>(
      builder: (context, incomeData, child) {
        var incomeDataSource =
            IncomeGridSource(incomeData: incomeData.getIncomeList());
        return Scaffold(
          body: SafeArea(
            child: SfDataGrid(
              source: incomeDataSource,
              columnWidthMode: ColumnWidthMode.fill,
              columns: <GridColumn>[
                GridTextColumn(
                  columnName: 'source',
                  label: Container(
                    color: Colors.green,
                    padding: EdgeInsets.all(16.0),
                    alignment: Alignment.center,
                    child: Text(
                      'Source',
                      style: TextStyle(color: Colors.white),
                    ),
                  ),
                ),
                GridTextColumn(
                  columnName: 'gross',
                  label: Container(
                    color: Colors.green,
                    padding: EdgeInsets.all(8.0),
                    alignment: Alignment.center,
                    child: Text(
                      'Gross',
                      style: TextStyle(color: Colors.white),
                    ),
                  ),
                ),
                GridTextColumn(
                  columnName: 'cgi',
                  label: Container(
                    color: Colors.green,
                    padding: EdgeInsets.all(8.0),
                    alignment: Alignment.center,
                    child: Text(
                      'CGI',
                      style: TextStyle(color: Colors.white),
                      overflow: TextOverflow.ellipsis,
                    ),
                  ),
                ),
                GridTextColumn(
                  columnName: 'incomeDate',
                  label: Container(
                    color: Colors.green,
                    padding: EdgeInsets.all(8.0),
                    alignment: Alignment.center,
                    child: Text(
                      'Income Date',
                      style: TextStyle(color: Colors.white),
                    ),
                  ),
                ),
                GridTextColumn(
                  columnName: 'dateAdded',
                  label: Container(
                    color: Colors.green,
                    padding: EdgeInsets.all(8.0),
                    alignment: Alignment.center,
                    child: Text(
                      'Date Added',
                      style: TextStyle(color: Colors.white),
                    ),
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}

class IncomeGridSource extends DataGridSource {
  /// Creates the income data source class with required details.
  IncomeGridSource({@required List<Income> incomeData}) {
    _incomeData = incomeData
        .map<DataGridRow>(
          (income) => DataGridRow(
            cells: [
              DataGridCell<String>(columnName: 'source', value: income.source),
              DataGridCell<double>(columnName: 'gross', value: income.gross),
              DataGridCell<double>(columnName: 'cgi', value: income.cgi),
              DataGridCell<String>(
                  columnName: 'incomeDate',
                  value: DateFormat.yMMMd().format(income.incomeDate)),
              DataGridCell<String>(
                  columnName: 'dateAdded',
                  value: DateFormat.yMMMd().format(income.dateAdded)),
            ],
          ),
        )
        .toList();
  }

  List<DataGridRow> _incomeData = [];

  @override
  List<DataGridRow> get rows => _incomeData;

  @override
  DataGridRowAdapter buildRow(DataGridRow row) {
    Color getRowBackgroundColor() {
      final int index = _incomeData.indexOf(row);
      if (index % 2 == 0) {
        return Colors.green.shade100;
      }
      return Colors.transparent;
    }

    return DataGridRowAdapter(
        color: getRowBackgroundColor(),
        cells: row.getCells().map<Widget>((e) {
          return Container(
            alignment: Alignment.center,
            padding: EdgeInsets.all(8.0),
            child: Text(e.value.toString()),
          );
        }).toList());
  }
}
//
///
///收入数据网格-Syncfusion版本
进口“包装:颤振/材料.省道”;
导入“package:fp_provider_demo_one/models/income/income.dart”;
导入“package:fp_provider_demo_one/models/income/income_data.dart”;
导入“包:intl/intl.dart”;
导入“包:provider/provider.dart”;
导入“包:syncfusion_flatter_datagrid/datagrid.dart”;
类IncomeDataGrid扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
退货消费者(
生成器:(上下文、incomeData、child){
收入来源=
IncomeGridSource(incomeData:incomeData.getIncomeList());
返回脚手架(
正文:安全区(
子:SfDataGrid(
资料来源:IncomedatSource,
columnWidthMode:columnWidthMode.fill,
栏目:[
GridTextColumn(
columnName:'源',
标签:集装箱(
颜色:颜色。绿色,
填充:所有边缘设置(16.0),
对齐:对齐.center,
子:文本(
“来源”,
样式:TextStyle(颜色:Colors.white),
),
),
),
GridTextColumn(
columnName:'gross',
标签:集装箱(
颜色:颜色。绿色,
填充:边缘设置。全部(8.0),
对齐:对齐.center,
子:文本(
“总量”,
样式:TextStyle(颜色:Colors.white),
),
),
),
GridTextColumn(
columnName:'cgi',
标签:集装箱(
颜色:颜色。绿色,
填充:边缘设置。全部(8.0),
对齐:对齐.center,
子:文本(
“CGI”,
样式:TextStyle(颜色:Colors.white),
溢出:TextOverflow.省略号,
),
),
),
GridTextColumn(
columnName:'incomeDate',
标签:集装箱(
颜色:颜色。绿色,
填充:边缘设置。全部(8.0),
对齐:对齐.center,
子:文本(
“收入日期”,
样式:TextStyle(颜色:Colors.white),
),
),
),
GridTextColumn(
columnName:'已添加日期',
标签:集装箱(
颜色:颜色。绿色,
填充:边缘设置。全部(8.0),
对齐:对齐.center,
子:文本(
“添加日期”,
样式:TextStyle(颜色:Colors.white),
),
),
),
],
),
),
);
},
);
}
}
类IncomeGridSource扩展了DataGridSource{
///创建包含所需详细信息的收入数据源类。
IncomeGridSource({@required List incomeData}){
_incomeData=incomeData
.地图(
(收入)=>DataGridRow(
单元格:[
DataGridCell(columnName:'source',值:income.source),
DataGridCell(列名:'gross',值:income.gross),
DataGridCell(列名:“cgi”,值:income.cgi),
数据网格单元(
columnName:'incomeDate',
值:DateFormat.yMMMd().format(income.incomeDate)),
数据网格单元(
columnName:'已添加日期',
值:DateFormat.yMMMd().format(income.dateAdded)),
],
),
)
.toList();
}
清单_incomeData=[];
@凌驾
列表获取行=>\u incomeData;
@凌驾
DataGridRow适配器构建行(DataGridRow行){
颜色getRowBackgroundColor(){
最终整数索引=_incomeData.indexOf(行);
如果(索引%2==0){
返回Colors.green.shade100;
}
返回颜色。透明;
}
返回DataGridRowAdapter(
颜色:getRowBackgroundColor(),
赛尔
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:syncfusion_flutter_datagrid/datagrid.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(
            create: (_) => EmployeeDataSource())
      ],
      child: MaterialApp(
        title: 'Syncfusion DataGrid Demo',
        theme: ThemeData(primarySwatch: Colors.blue),
        home: SkyRocketingIssue(),
      ),
    );
  }
}

class SkyRocketingIssue extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Consumer<EmployeeDataSource>(
      builder: (context, employeeDataSource, _) {
        return Scaffold(
          appBar: AppBar(
            title: Text('DataGrid Demo'),
          ),
          body: SfDataGrid(
            source: employeeDataSource,
            columnWidthMode: ColumnWidthMode.fill,
            selectionMode: SelectionMode.multiple,
            navigationMode: GridNavigationMode.cell,
            allowEditing: true,
            // controller: dataGridController,
            onQueryRowHeight: (details) {
              return details.rowHeight;
            },
            columns: <GridColumn>[
              GridTextColumn(
                  columnName: 'id',
                  label: Container(
                      padding: EdgeInsets.all(16.0),
                      alignment: Alignment.centerRight,
                      child: Text(
                        'ID',
                      ))),
              GridTextColumn(
                  columnName: 'name',
                  label: Container(
                      padding: EdgeInsets.all(16.0),
                      alignment: Alignment.centerLeft,
                      child: Text('Name'))),
              GridTextColumn(
                  columnName: 'designation',
                  width: 120,
                  label: Container(
                      padding: EdgeInsets.all(16.0),
                      alignment: Alignment.centerLeft,
                      child: Text('Designation'))),
              GridTextColumn(
                  columnName: 'salary',
                  label: Container(
                      padding: EdgeInsets.all(16.0),
                      alignment: Alignment.centerRight,
                      child: Text('Salary'))),
            ],
          ),
        );
      },
    );
  }
}

/// Custom business object class which contains properties to hold the detailed
/// information about the employee which will be rendered in datagrid.
class Employee {
  /// Creates the employee class with required details.
  Employee(this.id, this.name, this.designation, this.salary);

  /// Id of an employee.
  int id;

  /// Name of an employee.
  String name;

  /// Designation of an employee.
  String designation;

  /// Salary of an employee.
  int salary;
}

/// An object to set the employee collection data source to the datagrid. This
/// is used to map the employee data to the datagrid widget.
class EmployeeDataSource extends DataGridSource {
  /// Creates the employee data source class with required details.
  EmployeeDataSource(){
    employees = getEmployeeData();
    buildDataGridRow();
  }

  void buildDataGridRow() {
    dataGridRows = employees
        .map<DataGridRow>((e) => DataGridRow(cells: [
              DataGridCell<int>(columnName: 'id', value: e.id),
              DataGridCell<String>(columnName: 'name', value: e.name),
              DataGridCell<String>(
                  columnName: 'designation', value: e.designation),
              DataGridCell<int>(columnName: 'salary', value: e.salary),
            ]))
        .toList();
  }

  List<Employee> employees = <Employee>[];

  List<DataGridRow> dataGridRows = [];

  @override
  List<DataGridRow> get rows => dataGridRows;

  @override
  DataGridRowAdapter buildRow(DataGridRow row) {
    return DataGridRowAdapter(
        cells: row.getCells().map<Widget>((e) {
      return Container(
        alignment: (e.columnName == 'id' || e.columnName == 'salary')
            ? Alignment.centerRight
            : Alignment.centerLeft,
        padding: EdgeInsets.all(8.0),
        child: Text(e.value.toString()),
      );
    }).toList());
  }

  List<Employee> getEmployeeData() {
    return [
      Employee(10001, 'James', 'Project Lead', 20000),
      Employee(10002, 'Kathryn', 'Manager', 30000),
      Employee(10003, 'Lara', 'Developer', 15000),
      Employee(10004, 'Michael', 'Designer', 15000),
      Employee(10005, 'Martin', 'Developer', 15000),
      Employee(10006, 'Newberry', 'Developer', 15000),
      Employee(10007, 'Balnc', 'Developer', 15000),
      Employee(10008, 'Perry', 'Developer', 15000),
      Employee(10009, 'Gable', 'Developer', 15000),
      Employee(10010, 'Grimes', 'Developer', 15000),
      Employee(10010, 'Lane', 'Project Lead', 20000),
      Employee(10010, 'Doran', 'Developer', 15000),
      Employee(10010, 'Betts', 'Developer', 15000),
      Employee(10010, 'Tamer', 'Manager', 30000),
      Employee(10001, 'James', 'Project Lead', 20000),
      Employee(10002, 'Kathryn', 'Manager', 30000),
      Employee(10003, 'Lara', 'Developer', 15000),
      Employee(10004, 'Michael', 'Designer', 15000),
      Employee(10005, 'Martin', 'Developer', 15000),
      Employee(10006, 'Newberry', 'Developer', 15000),
      Employee(10007, 'Balnc', 'Developer', 15000),
      Employee(10008, 'Perry', 'Developer', 15000),
      Employee(10009, 'Gable', 'Developer', 15000),
      Employee(10010, 'Grimes', 'Developer', 15000),
      Employee(10010, 'Lane', 'Project Lead', 20000),
      Employee(10010, 'Doran', 'Developer', 15000),
      Employee(10010, 'Betts', 'Developer', 15000),
      Employee(10010, 'Tamer', 'Manager', 30000),
    ];
  }
}