ali_loyalty_flutter 1.0.0+200525 copy "ali_loyalty_flutter: ^1.0.0+200525" to clipboard
ali_loyalty_flutter: ^1.0.0+200525 copied to clipboard

A new flutter plugin project.

example/lib/main.dart

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

import 'package:ali_loyalty_flutter/ali_loyalty_flutter.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(primarySwatch: Colors.blue, fontFamily: "NunitoSans"),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final clientId = "42486";
  final phone = "0949194668";
  final fullname = "Vu Ho Mlo";

  final apiKey = "c4ca4238a0b923820dcc509a6f75849b";
  final apiSecret = "3792b218b5a17487da14abb94bb7b4ef";

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

    _getCurrentLocation();
  }

  Future<void> _getCurrentLocation() async {
    try {
      var location = Location();
      if (await location.serviceEnabled()) {
        bool success =
            await location.hasPermission() == PermissionStatus.GRANTED;
        if (!success) {
          success =
              await location.requestPermission() == PermissionStatus.GRANTED;
        }

        if (success) {
          LocationData data = await location.getLocation();
          AliLoyalty().auth(
              appName: "TOT Loyalty",
              apiKey: apiKey,
              apiSecret: apiSecret,
              clientId: clientId,
              phone: phone,
              fullname: fullname,
              currentLat: data.latitude,
              currentLng: data.longitude,
              language: "vi");
        } else {
          throw Exception;
        }
      } else {
        throw Exception;
      }
    } catch (_) {}
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      body: AliLoyalty().widget(onBack: () {
        debugPrint("on go back");
      }),
    );
  }
}