tight_flutter 0.0.1
tight_flutter: ^0.0.1 copied to clipboard
Flutter bridge to the Tight mileage tracking SDKs (iOS and Android) via platform channels: permissions, detection modes, semi-auto drives and a stream of native drive events.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:tight_flutter/tight_flutter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(home: TightDemoPage());
}
}
class TightDemoPage extends StatefulWidget {
const TightDemoPage({super.key});
@override
State<TightDemoPage> createState() => _TightDemoPageState();
}
class _TightDemoPageState extends State<TightDemoPage> {
final TightFlutter _tight = TightFlutter();
StreamSubscription<TightEvent>? _eventsSub;
String _status = 'Not initialized';
TightPermissions? _permissions;
TightDrive? _currentDrive;
TightEvent? _lastEvent;
@override
void initState() {
super.initState();
_eventsSub = _tight.events.listen((TightEvent event) {
setState(() => _lastEvent = event);
});
}
@override
void dispose() {
_eventsSub?.cancel();
super.dispose();
}
Future<void> _run(String label, Future<void> Function() action) async {
try {
await action();
setState(() => _status = '$label: OK');
} on TightException catch (e) {
setState(() => _status = '$label: ${e.code} ${e.message ?? ''}');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('tight_flutter demo')),
body: ListView(
padding: const EdgeInsets.all(16),
children: <Widget>[
Text('Status: $_status'),
const SizedBox(height: 8),
Text('Permissions: ${_permissions ?? '—'}'),
Text('Current drive: ${_currentDrive ?? '—'}'),
Text('Last event: ${_lastEvent?.runtimeType ?? '—'}'),
const Divider(height: 32),
FilledButton(
onPressed: () => _run(
'initialize',
() => _tight.initialize(accessToken: 'demo-token'),
),
child: const Text('initialize'),
),
FilledButton(
onPressed: () => _run('requestPermissions', () async {
final TightPermissions p = await _tight
.requestMileagePermissions();
setState(() => _permissions = p);
}),
child: const Text('requestMileagePermissions'),
),
FilledButton(
onPressed: () => _run(
'automatic mode',
() => _tight.setMileageDetectionMode(
MileageDetectionMode.automatic,
),
),
child: const Text('setMode(automatic)'),
),
FilledButton(
onPressed: () =>
_run('startSemiAutoDrive', _tight.startSemiAutoDrive),
child: const Text('startSemiAutoDrive'),
),
FilledButton(
onPressed: () => _run('stopDrive', _tight.stopDrive),
child: const Text('stopDrive'),
),
FilledButton(
onPressed: () => _run('getCurrentDrive', () async {
final TightDrive? d = await _tight.getCurrentDrive();
setState(() => _currentDrive = d);
}),
child: const Text('getCurrentDrive'),
),
],
),
);
}
}