gpt4 book ai didi

flutter - 日期倒数计时器

转载 作者:行者123 更新时间:2023-12-03 03:30:16 24 4
gpt4 key购买 nike

我正在尝试对日期进行倒计时,并将每个倒计时放在 ListView 的 ItemView 中。我已经有了 Listview.buillder() 但我不知道如何制作具有不同值的倒计时并将它们放在 Listview 中。我看到还有另一个类似的问题,但我无法用它解决我的问题。

这是我的代码:home_screen.dart

import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
import '../recyclerview/data.dart';
import 'package:watch/constants.dart';

int itemCount = item.length;
List<bool> selected = new List<bool>();

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

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

class _MyHomePageState extends State<MyHomePage> {
@override
initState() {
for (var i = 0; i < itemCount; i++) {
selected.add(false);
}
super.initState();
}

Icon notFavorite = Icon(Icons.favorite_border, size: 30,);
Icon inFavorite = Icon(Icons.favorite, size: 30,);

@override
Widget build(BuildContext context) {
int estimateTs = DateTime(2021, 11, 5, 7, 15, 30).millisecondsSinceEpoch;
return new Scaffold(
appBar: AppBar(
title: Text('Accueil', style: kAppBarStyle,),
//backgroundColor: Colors.white,
elevation: 0,
automaticallyImplyLeading: false,
),
body: ListView.builder(
scrollDirection: Axis.vertical,
physics: BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
itemCount: itemCount,
itemBuilder: (BuildContext context, int index) {
return Container(
child: new Row(
children: <Widget>[
//Image
new Container(
margin: new EdgeInsets.only(top: 5.0, left: 1.0),
child: new CachedNetworkImage(
imageUrl: item[index].imageURL,
height: MediaQuery.of(context).size.width / 3,
width: MediaQuery.of(context).size.width / 2,
fit: BoxFit.cover,
),
),
//Text
Expanded(
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Spacer(),
//Titre
Container(
padding: const EdgeInsets.only(bottom: 75.0, top: 8.0 ),
child: Text(
item[index].title,
style: kItemTitle,
),
),
//Decription
Container(
padding: const EdgeInsets.only(left: 10.0, top: 8.0),
child:Text(
item[index].description,
style: kItemDescription,
),
),
//Favoris
Spacer(),
GestureDetector(
child: Container(
padding: const EdgeInsets.only(right: 10.0, top: 0.0),
child: selected.elementAt(index) ? inFavorite : notFavorite,
),
onTap: () {
setState(() {
selected[index] = !selected.elementAt(index);
});
},
),
],
),
),

],
),
);
}
)
);
}
}

最佳答案

您需要使用 Timer像这样。

void startTimer() {
// Start the periodic timer which prints something every 1 seconds
timer= new Timer.periodic(new Duration(seconds: 1), (time) {
print('Something');

});
}

您可以阅读 more .对了,有个励志包,你可以试试flutter_countdown_timer .

关于flutter - 日期倒数计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64451276/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com