2024年1月24日发(作者:)
Flutter倒计时功能import 'dart:async';import 'package:flutter/';import 'package:flutter/';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: , ), home: Scaffold( appBar: AppBar(title: Text('倒计时'),), body: MyHomePage(), ) ); }}class MyHomePage extends StatefulWidget { @override _MyHomePageState createState() => _MyHomePageState();}class _MyHomePageState extends State
RaisedButton( child: Text('开始倒计时'), onPressed: () { if (countdownTimer != null) { return; } countdownTimer = new ic(new Duration(seconds: 1), (timer) { setState(() { if (seconds > 0) { seconds--; } else { (); countdownTimer = null; } }); }); }, ), Text( '倒计时: $seconds' + '秒', style: TextStyle(fontSize: 30), ), ], ), )
); }}


发布评论