搜尋套件、儲存庫與 APP 分類

GitHub 儲存庫pablo-co/flutter_true_time

flutter_true_time

pablo-co/flutter_true_time open-source repository details.

flutter_true_time 專案封面
星標
9
分支
20
最近推送(UTC)
2024年7月8日
專案狀態
未封存

原始 README

以下為英文專案原文快照,最新內容請造訪 GitHub。

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 `/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'),
          ],
        ),
      ),
    );
  }
}
Pablo Cárdenas GitHub avatar
GitHub 作者

Pablo Cárdenas ↗

語言DartRubyJavaSwiftObjective-C

使用的依賴

依賴清單 1 項

  • flutter{"sdk":"flutter"}

如何選擇適合專案的儲存庫?

先依使用情境篩選,再比較專案活躍情況,最後到原始儲存庫確認使用要求。

  1. 透過儲存庫名稱、作者或描述搜尋,再依技術分類縮小範圍。
  2. 綜合星標、分支與最近推送比較專案;星標反映社群關注,不保證品質。
  3. 使用前在 GitHub 確認 README、授權條款與 Issues。

來源與維護

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗