cloudbase_null_safety 1.1.0 copy "cloudbase_null_safety: ^1.1.0" to clipboard
cloudbase_null_safety: ^1.1.0 copied to clipboard

outdated

Flutter plugin for cloudbase core. Temporary alternative to the official null-safety version, all APIs are consistent with the official.

example/lib/main.dart

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

import 'package:flutter/services.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformTest = 'Unknown';
  String _log = "";
  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

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

    // 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(() {
      _platformTest = platformTest;
    });
  }

  @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: [
              TextButton(onPressed: () async{
                log("go");
                CloudBaseCore core = CloudBaseCore.init({
                  // 填写你的云开发envId和微信开放平台Appid
                  'env': 'xxx',  
                  'appAccess': {
                    'key': 'xxxxxx',
                    'test': 'x'
                  }
                });
                // CloudBase微信登录
                CloudBaseAuth auth = CloudBaseAuth(core);
                
                CloudBaseAuthState? state = await auth.getAuthState();
                if (state != null) {
                  log("ok");
                }
                else{
                  await auth.signInByWx(wxAppId: "wxXXXX", wxUniLink: "xxx").then((success) {
                      // 登录成功
                      log("登录成功");
                      auth.getUserInfo();
                  }).catchError((err) {
                      // 登录失败
                      log("登录失败 $err");
                  });
                }
              }, child: Text('Running on: $_platformTest\n')),
              Text(_log, style: Theme.of(context).textTheme.headline5,)
            ],
          ),
        ),
      ),
    );
  }

  void log(String val){
    setState(() {
      _log = val;
    });
  }
}
8
likes
0
pub points
21%
popularity

Publisher

unverified uploader

Flutter plugin for cloudbase core. Temporary alternative to the official null-safety version, all APIs are consistent with the official.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

crypto, dio, flutter, package_info, shared_preferences

More

Packages that depend on cloudbase_null_safety