true_time 0.1.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 78

TrueTime - NTP plugin for Flutter

pub package

Calculate the date and time "now" impervious to manual changes to device clock time.

In certain applications it becomes important to get the real or "true" date and time. On most devices, if the clock has been changed manually, then a new DateTime instance gives you a time impacted by local settings.

Users may do this for a variety of reasons, like being in different timezones, trying to be punctual by setting their clocks 5 – 10 minutes early, etc. Your application or service may want a date that is unaffected by these changes and reliable as a source of truth. TrueTime gives you that.

This plugin is based on truetime in Android and TrueTime in iOS for the whole SNTP protocol implementation.

Installation

Just add true_time as a dependency in your pubspec.yaml file.

Android

Ensure the following permission is present in your Android Manifest file, located in <project root>/android/app/src/main/AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET"/>

The Flutter project template adds it, so it may already be there.

iOS

Already good to go.

Example

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'),
          ],
        ),
      ),
    );
  }
}

[0.1.0]

  • Allow configuration of the SNTP request ([#2][2])

[0.0.2]

  • Fix compilation error due to missing import (#1)

[0.0.1]

  • Initial release

example/README.md

true_time_example

Demonstrates how to use the true_time plugin.

Getting Started

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  true_time: ^0.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:true_time/true_time.dart';
  
Version Uploaded Documentation Archive
0.1.0 Nov 14, 2018 Go to the documentation of true_time 0.1.0 Download true_time 0.1.0 archive
0.0.2 Jul 18, 2018 Go to the documentation of true_time 0.0.2 Download true_time 0.0.2 archive
0.0.1 Jul 18, 2018 Go to the documentation of true_time 0.0.1 Download true_time 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
56
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
78
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7
  • Flutter: 1.0.0

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8