teliverflutter 1.0.1 copy "teliverflutter: ^1.0.1" to clipboard
teliverflutter: ^1.0.1 copied to clipboard

Teliver Flutter SDK.

example/lib/main.dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:teliverflutter/teliverflutter.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  final _teliverflutterPlugin = Teliverflutter();
  var textInput = TextEditingController();

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    var result = _teliverflutterPlugin.initSDK("YOUR_TELIVER_KEY");
    _teliverflutterPlugin.setLogVisible(true);
    //  _teliverflutterPlugin.identifyUser("Test User");

    if (kDebugMode) {
      print("CONNECTION LISTENER ::  :::::::::::: ");
      print(result);
    }
    if (!mounted) return;
    setState(() {
      //_platformVersion = platformVersion;
    });
  }

  Future<void> onStartStopTrack(bool isTrack) async {
    var result;
    if (textInput.text.trim().isNotEmpty) {
      try {
        if (isTrack) {
          result = await _teliverflutterPlugin
              .startTracking(textInput.text.toString());
          print(result);
        } else {
          result =
              _teliverflutterPlugin.stopTracking(textInput.text.toString());
        }
        if (kDebugMode) {
          print("ON START STOP RESULT MEHTOD CALLING :::: ");
          print(result);
        }
      } on Exception catch (exception) {
        exception.runtimeType;
      }
    } else {
      if (kDebugMode) print("Enter TRIP ID");
    }
  }

  Future<void> onStartStopTrip(bool isStart) async {
    if (kDebugMode) {
      print("FROM INSIDE ON START STOP TRIP ");
    }
    if (textInput.text.trim().isNotEmpty) {
      try {
        var result;
        if (isStart) {
          result =
              await _teliverflutterPlugin.startTrip(textInput.text.toString());
        } else {
          result =
              await _teliverflutterPlugin.stopTrip(textInput.text.toString());
        }
        if (kDebugMode) {
          print("ON START STOP RESULT MEHTOD CALLING :::: ");
          print(result);
        }
      } on Exception catch (exception) {
        exception.runtimeType;
      }
    } else {
      if (kDebugMode) print("Enter TRIP ID");
    }
  }

  Future<void> onStartStopMultipleTracking(bool isTrack) async {
    if (textInput.text.trim().isNotEmpty) {
      try {
        if (isTrack) {
          _teliverflutterPlugin.startMultiTracking(textInput.text.toString());
        } else {
          _teliverflutterPlugin.stopMultiTracking(textInput.text.toString());
        }
      } on Exception catch (exception) {
        exception.runtimeType;
      }
    } else {
      if (kDebugMode) print("Enter TRIP ID");
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Container(
                margin: const EdgeInsets.all(10),
                padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(5),
                  color: Colors.grey.shade300,
                ),
                child: TextField(
                  controller: textInput,
                  decoration: const InputDecoration(
                      border: InputBorder.none, hintText: "Enter a Trip ID"),
                ),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  ElevatedButton(
                    onPressed: () {
                      onStartStopTrack(true);
                    },
                    child: const Text("Start tracking"),
                  ),
                  const SizedBox(
                    width: 15,
                  ),
                  ElevatedButton(
                    onPressed: () {
                      onStartStopTrack(false);
                    },
                    child: const Text("Stop tracking"),
                  ),
                ],
              ),
              const SizedBox(
                height: 20,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  ElevatedButton(
                    onPressed: () {
                      onStartStopTrip(true);
                    },
                    child: const Text("Start Trip"),
                  ),
                  const SizedBox(
                    width: 15,
                  ),
                  ElevatedButton(
                    onPressed: () {
                      onStartStopTrip(false);
                    },
                    child: const Text("Stop trip"),
                  ),
                ],
              ),
              const SizedBox(
                height: 20,
              ),
              Column(
                children: [
                  ElevatedButton(
                    onPressed: () {
                      onStartStopMultipleTracking(true);
                    },
                    child: const Text("Start Multiple Tracking"),
                  ),
                  const SizedBox(
                    width: 15,
                  ),
                  ElevatedButton(
                    onPressed: () {
                      onStartStopMultipleTracking(false);
                    },
                    child: const Text("Stop Multiple Tracking"),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
130
points
1
downloads

Publisher

unverified uploader

Weekly Downloads

Teliver Flutter SDK.

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on teliverflutter

Packages that implement teliverflutter