diff --git a/android/src/main/java/com/lunagao/leancloudflutterplugin/LeancloudUser.java b/android/src/main/java/com/lunagao/leancloudflutterplugin/LeancloudUser.java new file mode 100644 index 0000000..7e06d83 --- /dev/null +++ b/android/src/main/java/com/lunagao/leancloudflutterplugin/LeancloudUser.java @@ -0,0 +1,14 @@ +package com.lunagao.leancloudflutterplugin; + +import cn.leancloud.AVUser; +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; + +public class LeancloudUser { + + void getCurrentUser(MethodCall call, final MethodChannel.Result result) { + AVUser currentUser = AVUser.getCurrentUser(); + result.success(currentUser.toJSONString()); + } + +} diff --git a/example/lib/list_screen.dart b/example/lib/list_screen.dart index f0c5392..f5fdae4 100644 --- a/example/lib/list_screen.dart +++ b/example/lib/list_screen.dart @@ -3,6 +3,8 @@ import 'package:flutter/material.dart'; import 'package:leancloud_flutter_plugin/leancloud_object.dart'; import 'package:leancloud_flutter_plugin/leancloud_query.dart'; +import 'user_screen.dart'; + class ListScreen extends StatefulWidget { @override _ListScreenState createState() => _ListScreenState(); @@ -121,6 +123,16 @@ class _ListScreenState extends State { onPressed: _queryByCQL, child: Text('query by CQL'), ), + Text('login function'), + FlatButton( + onPressed: () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) => UserScreen()), + ); + }, + child: Text('LOGIN'), + ), ], ) ); diff --git a/example/lib/user_screen.dart b/example/lib/user_screen.dart new file mode 100644 index 0000000..40a6c09 --- /dev/null +++ b/example/lib/user_screen.dart @@ -0,0 +1,33 @@ +import 'package:flutter/material.dart'; + +class UserScreen extends StatefulWidget { + @override + _UserScreenState createState() => _UserScreenState(); +} + +class _UserScreenState extends State { + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('User Page'), + ), + body: ListView( + shrinkWrap: true, + padding: const EdgeInsets.all(20.0), + children: [ + Text("Please click 'create an Object' button"), + FlatButton( + onPressed: () {}, + child: Text('Sign in'), + ), + FlatButton( + onPressed: () {}, + child: Text('Login in'), + ) + ], + ) + ); + } +} \ No newline at end of file diff --git a/lib/leancloud_flutter_plugin.dart b/lib/leancloud_flutter_plugin.dart index 4426532..7da6c22 100644 --- a/lib/leancloud_flutter_plugin.dart +++ b/lib/leancloud_flutter_plugin.dart @@ -120,6 +120,12 @@ class LeancloudFlutterPlugin { var args = {'cql': cql}; return await _channel.invokeMethod('doCloudQuery', args); } + + /// Get current User + Future currentUser() async { + var currentUserJson = await _channel.invokeMethod('currentUser'); + return currentUserJson; + } } /// Leancloud logger level diff --git a/lib/leancloud_user.dart b/lib/leancloud_user.dart new file mode 100644 index 0000000..d8d9b0e --- /dev/null +++ b/lib/leancloud_user.dart @@ -0,0 +1,15 @@ +import 'package:leancloud_flutter_plugin/leancloud_flutter_plugin.dart'; +import 'package:leancloud_flutter_plugin/leancloud_object.dart'; + +class AVUser extends AVObject{ + + var _userName; + + AVUser() : super("_User"); + +// AVUser currentUser() { +// var leancloudFlutterPlugin = LeancloudFlutterPlugin.getInstance(); +// String jsonString = leancloudFlutterPlugin.currentUser(); +// return leancloudFlutterPlugin.currentUser(); +// } +} \ No newline at end of file