timercounter 0.0.4 copy "timercounter: ^0.0.4" to clipboard
timercounter: ^0.0.4 copied to clipboard

outdated

倒计时工具.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:timercounter/timercounter.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,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: Home(),
    );
  }
}

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  TimerCounter _timeCounter;
  int counter = 10;

  @override
  void dispose() {
    _timeCounter.stop();
    super.dispose();
  }

  void _beginTimer() {
    _timeCounter = TimerCounter.begin(duration: counter, callback: (index){
      setState(() {
        counter = index == 0 ? 10 : index;
      });
    });
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text("$counter++"),
            RaisedButton(
              child: Text("begin"),
              onPressed: _beginTimer,
            ),
            RaisedButton(
              child: Text("stop"),
              onPressed: () => _timeCounter.stop(),
            )
          ],
        ),
      ),
    );
  }
}
1
likes
0
pub points
23%
popularity

Publisher

unverified uploader

倒计时工具.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on timercounter