Skip to content

Commit

Permalink
add user screen example
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaGao committed Jan 10, 2019
1 parent 2f3c6e0 commit 045f4ce
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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());
}

}
12 changes: 12 additions & 0 deletions example/lib/list_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -121,6 +123,16 @@ class _ListScreenState extends State<ListScreen> {
onPressed: _queryByCQL,
child: Text('query by CQL'),
),
Text('login function'),
FlatButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => UserScreen()),
);
},
child: Text('LOGIN'),
),
],
)
);
Expand Down
33 changes: 33 additions & 0 deletions example/lib/user_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';

class UserScreen extends StatefulWidget {
@override
_UserScreenState createState() => _UserScreenState();
}

class _UserScreenState extends State<UserScreen> {

@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: <Widget>[
Text("Please click 'create an Object' button"),
FlatButton(
onPressed: () {},
child: Text('Sign in'),
),
FlatButton(
onPressed: () {},
child: Text('Login in'),
)
],
)
);
}
}
6 changes: 6 additions & 0 deletions lib/leancloud_flutter_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ class LeancloudFlutterPlugin {
var args = <String, String>{'cql': cql};
return await _channel.invokeMethod('doCloudQuery', args);
}

/// Get current User
Future<String> currentUser() async {
var currentUserJson = await _channel.invokeMethod('currentUser');
return currentUserJson;
}
}

/// Leancloud logger level
Expand Down
15 changes: 15 additions & 0 deletions lib/leancloud_user.dart
Original file line number Diff line number Diff line change
@@ -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();
// }
}

0 comments on commit 045f4ce

Please sign in to comment.