如何在扑打期间设置星期间隔日期,例如3个月的2019年1月3日,2019年1月10日和2019年1月17日?

时间:2019-01-03 04:30:47

标签: flutter

如何在扑打期间生成星期间隔日期,例如3个月的2019年1月3日,2019年1月10日和2019年1月17日?

*This is my code*
import 'package:flutter/material.dart';


class ListPage extends StatefulWidget {
  @override
  _ListPageState createState() => _ListPageState();
}

class _ListPageState extends State<ListPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: new AppBar(
        title: new Text('Repayment Schedule'),
        centerTitle: true,
      ),
      body: getListView('Total Payment', 'Ghs 100'),
    );
  }
}

List<String> getDateElement() {

  var _startingDate = DateTime.now();

  DateTime _newDate = _startingDate.add(Duration(days: 7));
  var dates = List<String>.generate(24,(counter)=> "$_newDate");
  return dates;
}



List<String> getListElement() {

  var item = List<String>.generate(24, (counter)=> "Week $counter");
  return item;
}

Widget getListView( String totalPmt, String amount,) {

  var listItems = getListElement();
  var listDates = getDateElement();

  var listView = ListView.builder(
    itemCount: listItems.length,
    itemBuilder: (context, index) {

      return Card(
        child: ListTile(
          leading: Text(listItems[index]),
          title: new Text(totalPmt),
          subtitle: Text(amount),
          trailing: Text(listDates[index]),
        ),
      );
    }
  );

  return listView;
}

我想要这样的1, 我得到的是2

我如何获得第一个结果,谢谢。我已经尝试了一段时间了。我是新来的。

2 个答案:

答案 0 :(得分:1)

DateTime _newDate = _startingDate.add(Duration(days: 7));

然后循环播放,直到您达到最大日期为止。

答案 1 :(得分:0)

您没有在生成器中使用counter来提前日期。试试:

 List<String> getDates() {
  DateTime now = DateTime.now();
  return List.generate(
      24, (counter) => now.add(Duration(days: counter * 7)).toString());
}
相关问题