true_time 0.1.0 copy "true_time: ^0.1.0" to clipboard
true_time: ^0.1.0 copied to clipboard

NTP library for Flutter. Get the true time impervious to device clock changes.

example/lib/main.dart

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

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _initialized = false;
  DateTime _currentTime;

  @override
  initState() {
    super.initState();
    _initPlatformState();
  }

  _initPlatformState() async {
    bool initialized = await TrueTime.init();
    setState(() {
      _initialized = initialized;
    });
    _updateCurrentTime();
  }

  _updateCurrentTime() async {
    DateTime now = await TrueTime.now();
    setState(() {
      _currentTime = now;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        floatingActionButton: new FloatingActionButton(
          tooltip: 'Get current time',
          child: new Icon(Icons.timer),
          onPressed: _updateCurrentTime,
        ),
        appBar: new AppBar(
          title: new Text('Example TrueTime app'),
        ),
        body: new Column(
          children: <Widget>[
            new Text('TrueTime is initialized: $_initialized\n'),
            new Text('Current Time: $_currentTime\n'),
          ],
        ),
      ),
    );
  }
}
17
likes
30
points
23
downloads

Publisher

unverified uploader

Weekly Downloads

NTP library for Flutter. Get the true time impervious to device clock changes.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on true_time