wecom_auth_plus 0.0.3
wecom_auth_plus: ^0.0.3 copied to clipboard
Flutter plugin for WeCom (Enterprise WeChat) auth. Supports configure, app-installed check, register, auth, and auto login flow.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:wecom_auth_plus/wecom_auth_plus.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _plugin = WecomAuthPlus();
String _log = 'Ready';
final _schemeController = TextEditingController(text: 'wwauth_xxx');
final _corpIdController = TextEditingController(text: 'wwxxxxxxxx');
final _agentIdController = TextEditingController(text: '1000001');
final _stateController = TextEditingController(text: 'example_state');
@override
void dispose() {
_schemeController.dispose();
_corpIdController.dispose();
_agentIdController.dispose();
_stateController.dispose();
super.dispose();
}
void _appendLog(String line) {
setState(() {
_log = '${DateTime.now().toIso8601String()}\n$line\n\n$_log';
});
}
Future<void> _configure() async {
await _plugin.configure(
scheme: _schemeController.text.trim(),
corpId: _corpIdController.text.trim(),
agentId: _agentIdController.text.trim(),
);
_appendLog('Configured');
}
Future<void> _isInstalled() async {
final r = await _plugin.isAppInstalled();
_appendLog('isInstalled: ${r.raw}');
}
Future<void> _register() async {
final r = await _plugin.register();
_appendLog('register: ${r.raw}');
}
Future<void> _auth() async {
final r = await _plugin.auth(state: _stateController.text.trim());
_appendLog('auth: ${r.raw}');
}
Future<void> _authAuto() async {
final r = await _plugin.authLoginAuto(
scheme: _schemeController.text.trim(),
corpId: _corpIdController.text.trim(),
agentId: _agentIdController.text.trim(),
state: _stateController.text.trim(),
);
_appendLog('authLoginAuto: ${r.raw}');
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Plugin example app')),
body: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TextField(
controller: _schemeController,
decoration: const InputDecoration(
labelText: 'scheme',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 8),
TextField(
controller: _corpIdController,
decoration: const InputDecoration(
labelText: 'corpId',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 8),
TextField(
controller: _agentIdController,
decoration: const InputDecoration(
labelText: 'agentId',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 8),
TextField(
controller: _stateController,
decoration: const InputDecoration(
labelText: 'state',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 12),
ElevatedButton(
onPressed: _configure,
child: const Text('1. configure'),
),
const SizedBox(height: 12),
ElevatedButton(
onPressed: _isInstalled,
child: const Text('2. isAppInstalled'),
),
const SizedBox(height: 12),
ElevatedButton(
onPressed: _register,
child: const Text('3. register'),
),
const SizedBox(height: 12),
ElevatedButton(onPressed: _auth, child: const Text('4. auth')),
const SizedBox(height: 12),
ElevatedButton(
onPressed: _authAuto,
child: const Text('5. authLoginAuto'),
),
const SizedBox(height: 20),
Expanded(child: SingleChildScrollView(child: Text(_log))),
],
),
),
),
);
}
}