honor_ly 0.0.1 copy "honor_ly: ^0.0.1" to clipboard
honor_ly: ^0.0.1 copied to clipboard

PlatformAndroid

荣耀联运sdk插件,包含荣耀登录,支付,广告

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:honor_ly/honor_ly.dart';
import 'package:honor_ly/honor_ly_platform_interface.dart';
import 'package:honor_ly_example/ad_page.dart';
import 'package:honor_ly_example/pay_page.dart';

// app id(sdk初始化,登录,支付)
const honorAppId = '9007***05';

// 广告
const honorAdAppId = '194609269***1542656';
const honorAppKey = 'QpsExk3gWEMtALn2aw24***CCVMIYrZWOD9EhYBEpGo=';

// 广告单元
const adBannerPosId = '19482054***74783232';
const adNativePosId = '19478610***52649984';
const adSplashPosId = '19461016***09038080';
const adInterPosId = '194610108***1762176';
const adRewardPosId = '19461015***67761408';

//支付
const honorCpId = '10999***2792';
const honorPublicKey =
    'MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAhvLKxyUqS9***vcLvHEgfzXbdCT2NfcN8t8MnExPNixtufji3Ii2rN5e82zRK6K7pkRJfp6R9hIk7/ddfOY4gA5l9RmarfuR3BBhFO7X9tPFC850AfvbmMuoFcpyq0Kl2nmKPWqw/Q5GxjoM3kz7scqgcZ954bPxo2uk6LKiEigoelhwoeIeZksi2QRWZrGlkNnxsee9kN9BEDEk4gsSQnEpHuTrwV4CFAW4Cdx5dxYBbBMcNA2ajbnqMEz9k63WDBvX5e1bw+Wo9xn6G1MagquJQkdXCFJUiO5Z7zQNTw11sQkyF5c9/+qivUwjcHR2XfG8RQWtpBjnaFC+BATXNHY7SEPrR5tL29Xp+Qa0JeU/gMl58DVAST8cuh9SlURKEEe5fQizOCrRhAjeP/gQ9eEp4SFhv7CylD5n+oJ8klQHgGHmP4r/+TpW98rHh5bsxoo1scM8RBdI4TMiPu6sml2Z7xR98eDBEKA0q9dUelLWqx93gwVRzHjbLMrNSznhAgMBAAE=';

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  bool _inited = false;
  bool _initPay = false;
  bool _initAd = false;
  bool _isLogined = false;
  String? _userInfo;
  final _honorLyPlugin = HonorLy();

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion =
          await _honorLyPlugin.getPlatformVersion() ??
          'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Builder(
        builder: (ctx) => Scaffold(
          appBar: AppBar(title: const Text('荣耀联运插件')),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisSize: MainAxisSize.max,
              children: [
                Text('Running on: $_platformVersion\n'),
                const SizedBox(height: 20),

                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text('初始化状态: $_inited'),
                    const SizedBox(width: 20),
                    FilledButton(
                      child: Text('初始化'),
                      onPressed: () async {
                        HonorLyPlatform.instance.init(honorAppId).then((v) {
                          setState(() {
                            _inited = v;
                          });
                        });
                      },
                    ),
                  ],
                ),
                const SizedBox(height: 20),

                Text('- - - - - - - - - - - - - - - - - - - - - - - -'),

                const SizedBox(height: 20),

                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text('初始化购买状态: $_initPay'),
                    const SizedBox(width: 20),
                    FilledButton(
                      child: Text('初始化购买'),
                      onPressed: () async {
                        HonorLyPlatform.instance
                            .initPay(honorAppId, honorCpId, sandBox: true)
                            .then((v) {
                              setState(() {
                                _initPay = v;
                              });
                              Navigator.of(ctx).push(
                                MaterialPageRoute(
                                  builder: (context) {
                                    return PayPage(title: 'PayPage');
                                  },
                                ),
                              );
                            });
                      },
                    ),
                  ],
                ),
                const SizedBox(height: 20),

                Text('- - - - - - - - - - - - - - - - - - - - - - - -'),

                const SizedBox(height: 20),

                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text('初始化广告状态: $_initAd'),
                    const SizedBox(width: 20),
                    FilledButton(
                      child: Text('初始化广告'),
                      onPressed: () async {
                        HonorLyPlatform.instance
                            .initAd(honorAdAppId, honorAppKey, useTest: true)
                            .then((v) {
                              setState(() {
                                _initAd = v;
                              });
                              Navigator.of(ctx).push(
                                MaterialPageRoute(
                                  builder: (context) {
                                    return AdPage(title: 'AdPage');
                                  },
                                ),
                              );
                            });
                      },
                    ),
                  ],
                ),
                const SizedBox(height: 20),

                Text('- - - - - - - - - - - - - - - - - - - - - - - -'),

                const SizedBox(height: 20),

                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text('登录状态: $_isLogined'),
                    const SizedBox(width: 20),
                    FilledButton(
                      child: Text('荣耀登录'),
                      onPressed: () {
                        HonorLyPlatform.instance.login().then((bd) {
                          debugPrint('登录结果:$bd');
                          if (bd != null) {
                            setState(() {
                              _userInfo = bd.toString();
                              _isLogined = true;
                            });
                          }
                        });
                      },
                    ),
                  ],
                ),
                const SizedBox(height: 20),

                Text('- - - - - - - - - - - - - - - - - - - - - - - -'),

                const SizedBox(height: 20),

                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text('用户信息: $_userInfo'),
                    const SizedBox(width: 20),
                    FilledButton(
                      child: Text('用户信息'),
                      onPressed: () async {
                        if (await HonorLyPlatform.instance.isLogined()) {
                          setState(() {
                            _isLogined = true;
                          });
                          HonorLyPlatform.instance.userInfo().then((bd) {
                            debugPrint('信息结果:$bd');
                            if (bd != null) {
                              setState(() {
                                _userInfo = bd.toString();
                                _isLogined = true;
                              });
                            }
                          });
                        } else {
                          debugPrint('请先登录账号!');
                          _showToast(ctx, '请先登录账号!');
                        }
                      },
                    ),
                  ],
                ),
                const SizedBox(height: 20),
              ],
            ),
          ),
        ),
      ),
    );
  }

  _showToast(BuildContext ctx, String msg) {
    ScaffoldMessenger.of(ctx).showSnackBar(
      SnackBar(
        content: Text(
          msg,
          textAlign: TextAlign.center,
          style: const TextStyle(fontWeight: FontWeight.bold),
        ),
        behavior: SnackBarBehavior.floating, // 可选:让 SnackBar 浮动
        margin: EdgeInsets.only(
          bottom:
              MediaQuery.of(ctx).size.height -
              MediaQuery.of(ctx).padding.top -
              100,
          left: 40,
          right: 40,
        ), // 调整顶部边距
      ),
    );
  }
}
2
likes
115
points
18
downloads

Publisher

unverified uploader

Weekly Downloads

荣耀联运sdk插件,包含荣耀登录,支付,广告

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on honor_ly

Packages that implement honor_ly