Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter Flatter配置单元:按日期按列表分组_Flutter_Dart_Flutter Hive - Fatal编程技术网

Flutter Flatter配置单元:按日期按列表分组

Flutter Flatter配置单元:按日期按列表分组,flutter,dart,flutter-hive,Flutter,Dart,Flutter Hive,我在和蜂巢颤振一起工作。我有一个这样的结果列表,但我希望按日期分组 结果我想要的,像这样: 1919年12月9日,星期一 ggh ggh ggh ggh 我已经研究过了,发现了一些包:。我尝试使用此脚本按列表分组,但打印不是我想要的: var groupData = groupBy(historyList, (obj) => historyList); print(historyList); 结果 I/flutter (23894): {2019-

我在和蜂巢颤振一起工作。我有一个这样的结果列表,但我希望按日期分组 结果我想要的,像这样:

1919年12月9日,星期一

  • ggh
  • ggh
  • ggh
  • ggh
我已经研究过了,发现了一些包:。我尝试使用此脚本按列表分组,但打印不是我想要的:

var groupData = groupBy(historyList, (obj) => historyList);
                  print(historyList);
结果

I/flutter (23894): {2019-12-09 01:08:56.328: [Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive']}
I/flutter (23894): {2019-12-09 00:57:22.455: [Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive']}
I/flutter (23894): {2019-12-09 00:57:01.274: [Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive']}
I/flutter (23894): {2019-12-09 00:56:56.992: [Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive']}
I/flutter (23894): {2019-12-09 00:56:47.549: [Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive']}
这是我的型号:

WatchBoxBuilder(
          box: Hive.box("history_box"),
          builder: (ctx, boxx) {
            final historyList = boxx.values.toList().cast<HistoryModelHive>();
            historyList.sort((first, end) =>
                end.dateHistoryCreate.compareTo(first.dateHistoryCreate));
            if (historyList.isEmpty) {
              return Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Image.asset(
                    "assets/images/empty2.png",
                    fit: BoxFit.cover,
                    height: 250,
                  ),
                  Text(
                    'Your History Empty',
                    textAlign: TextAlign.center,
                    style: textTheme.display1,
                  )
                ],
              );
            } else {
              return ListView.builder(
                itemCount: boxx.length,
                itemBuilder: (BuildContext context, int i) {
                  final historyData = historyList[i];
                  var groupData = groupBy(
                      historyList, (obj) => historyData.dateHistoryCreate);
                  print(groupData);
                  return ListViewHistory(
                    id: historyData.id,
                    receiverName: historyData.receiverName,
                    amountDebt: historyData.amountDebt,
                    amountLack: historyData.amountLack,
                    amountSubstract: historyData.amountSubstract,
                    dateHistoryCreate: historyData.dateHistoryCreate,
                    imageReceiver: historyData.imageReceiver,
                    imageSignature: historyData.imageSignature,
                    nameAction: historyData.nameAction,
                  );
                },
              );
            }
          },
        )),
WatchBoxBuilder(
盒子:Hive.box(“历史盒”),
建造商:(ctx,boxx){
最终历史列表=boxx.values.toList().cast();
historyList.sort((第一个,结束)=>
end.dateHistoryCreate.compareTo(first.dateHistoryCreate));
if(historyList.isEmpty){
返回列(
mainAxisAlignment:mainAxisAlignment.center,
crossAxisAlignment:crossAxisAlignment.center,
儿童:[
影像资产(
“assets/images/empty2.png”,
适合:BoxFit.cover,
身高:250,
),
正文(
“您的历史记录为空”,
textAlign:textAlign.center,
样式:textTheme.display1,
)
],
);
}否则{
返回ListView.builder(
itemCount:boxx.length,
itemBuilder:(构建上下文,int i){
最终历史数据=历史列表[i];
var groupData=groupBy(
historyList,(obj)=>historyData.dateHistoryCreate);
打印(组数据);
返回ListViewHistory(
id:historyData.id,
receiverName:historyData.receiverName,
amountDebt:historyData.amountDebt,
amountLack:historyData.amountLack,
amountSubstract:historyData.amountSubstract,
dateHistoryCreate:historyData.dateHistoryCreate,
imageReceiver:historyData.imageReceiver,
imageSignature:historyData.imageSignature,
nameAction:historyData.nameAction,
);
},
);
}
},
)),
您可以使用软件包
您可以复制粘贴运行下面的完整代码

代码片段

List<History> historyList = [History("Monday, December 9,2019", "gghh"), History("Monday, December 11,2019", "1"), History("Monday, December 10,2019", "2"), History("Monday, December 9,2019", "gghh"),History("Monday, December 9,2019", "gghh"),History("Monday, December 10,2019", "5") ];

  @override
  Widget build(BuildContext context) {
    return GroupedListView<History, String>(
      collection: historyList,
      groupBy: (History g) => g.dateHistoryCreate,
      listBuilder: (BuildContext context, History g) => ListTile(title: Text(g.amountDebt.toString())),
      groupBuilder: (BuildContext context, String name) => Text(name),
    );
  }
List historyList=[历史(“1919年12月9日星期一”,“gghh”)、历史(“2019年12月11日星期一”,“1”)、历史(“2019年12月10日星期一”,“2”)、历史(“2019年12月9日星期一”,“gghh”)、历史(“2019年12月10日星期一”,“5”);
@凌驾
小部件构建(构建上下文){
返回GroupedListView(
收藏品:史学家,
groupBy:(历史记录g)=>g.dateHistoryCreate,
listBuilder:(BuildContext上下文,历史记录g)=>ListTile(标题:Text(g.amountDebt.toString()),
groupBuilder:(BuildContext上下文,字符串名称)=>文本(名称),
);
}
演示

完整代码

import 'package:flutter/material.dart';
import 'package:grouped_listview/grouped_listview.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(        
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {      
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {   
    return Scaffold(
      appBar: AppBar(        
        title: Text(widget.title),
      ),
      body: Center(        
        child: Column(          
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Expanded(flex: 1, child: ExampleWidget()),
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), 
    );
  }
}

class History {
  String dateHistoryCreate;
  String amountDebt;

  History(this.dateHistoryCreate, this.amountDebt);
}

class ExampleWidget extends StatelessWidget {
  List<History> historyList = [History("Monday, December 9,2019", "gghh"), History("Monday, December 11,2019", "1"), History("Monday, December 10,2019", "2"), History("Monday, December 9,2019", "gghh"),History("Monday, December 9,2019", "gghh"),History("Monday, December 10,2019", "5") ];
  @override
  Widget build(BuildContext context) {
    return GroupedListView<History, String>(
      collection: historyList,
      groupBy: (History g) => g.dateHistoryCreate,
      listBuilder: (BuildContext context, History g) => ListTile(title: Text(g.amountDebt.toString())),
      groupBuilder: (BuildContext context, String name) => Text(name),
    );
  }
}
导入“包装:颤振/材料.省道”;
导入“package:grouped_listview/grouped_listview.dart”;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
//此小部件是应用程序的根。
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题资料(
主样本:颜色。蓝色,
),
主页:MyHomePage(标题:“颤振演示主页”),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
int _计数器=0;
void _incrementCounter(){
设置状态((){
_计数器++;
});
}
@凌驾
小部件生成(BuildContext上下文){
返回脚手架(
appBar:appBar(
标题:文本(widget.title),
),
正文:中心(
子栏(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
已扩展(flex:1,子项:ExampleWidget()),
正文(
“您已经按了这么多次按钮:”,
),
正文(
“$”计数器“,
样式:Theme.of(context).textTheme.display1,
),
],
),
),
浮动操作按钮:浮动操作按钮(
按下时:\ u递增计数器,
工具提示:“增量”,
子:图标(Icons.add),
), 
);
}
}
课堂历史{
字符串dateHistoryCreate;
巨额债务;
历史记录(this.dateHistoryCreate,this.amountDebt);
}
类ExampleWidget扩展了无状态Widget{
列表历史列表=[历史(“1919年12月9日,星期一”,“gghh”)、历史(“2019年12月11日,星期一”,“1”)、历史(“2019年12月10日,星期一”,“2”)、历史(“1919年12月9日,星期一”,“gghh”)、历史(“2019年12月10日,星期一”,“5”);
@凌驾
小部件构建(构建上下文){
返回GroupedListView(
收藏品:史学家,
groupBy:(历史记录g)=>g.dateHistoryCreate,
listBuilder:(BuildContext上下文,历史记录g)=>ListTile(标题:Text(g.amountDebt.toString()),
groupBuilder:(BuildContext上下文,字符串名称)=>文本(名称),
);
}
}
您可以使用软件包
您可以复制粘贴运行下面的完整代码

代码片段

List<History> historyList = [History("Monday, December 9,2019", "gghh"), History("Monday, December 11,2019", "1"), History("Monday, December 10,2019", "2"), History("Monday, December 9,2019", "gghh"),History("Monday, December 9,2019", "gghh"),History("Monday, December 10,2019", "5") ];

  @override
  Widget build(BuildContext context) {
    return GroupedListView<History, String>(
      collection: historyList,
      groupBy: (History g) => g.dateHistoryCreate,
      listBuilder: (BuildContext context, History g) => ListTile(title: Text(g.amountDebt.toString())),
      groupBuilder: (BuildContext context, String name) => Text(name),
    );
  }
List historyList=[历史(“1919年12月9日星期一”,“gghh”)、历史(“2019年12月11日星期一”,“1”)、历史(“2019年12月10日星期一”,“2”)、历史(“2019年12月9日星期一”,“gghh”)、历史(“2019年12月10日星期一”,“5”);
@凌驾
小部件构建(Bu)