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

LeanCloud Flutter plugin.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:leancloud/leancloud.dart';
import 'package:leancloud_example/avobject_page.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _MyAppState createState() {
    initializeLeanCloud();
    return _MyAppState();
  }

  Future<void> initializeLeanCloud() async {
    try {
      await Leancloud.initialize(
          "uYkM7rjLyJFyoGuzh6YCN1Fw-gzGzoHsz", "j7oplqXomohHWlRh1S0xovta");
    } on PlatformException catch (e, s) {
      print('Exception details:\n $e');
      print('Stack trace:\n $s');
    }
  }
}

class _MyAppState extends State<HomePage> {
  TextEditingController _usernameController = new TextEditingController();
  TextEditingController _passwordController = new TextEditingController();
  String _result = "";

  _signUp() async {
    bool result = false;
    try {
      result = await Leancloud.signUp(
          _usernameController.text, _passwordController.text);
    } on PlatformException catch (e, s) {
      print('Exception details:\n $e');
      print('Stack trace:\n $s');
    }

    setState(() {
      if (result) {
        _result = "注册成功";
      } else {
        _result = "注册失败";
      }
    });
  }

  _login() async {
    List<String> result;
    try {
      result = await Leancloud.login(
          _usernameController.text, _passwordController.text);
    } on PlatformException catch (e, s) {
      print('Exception details:\n $e');
      print('Stack trace:\n $s');
    }
//

    if (result == null) {
      _result = "登录失败";
    } else {
      _result = "登录成功";
      Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) {
        return AVObjectPage(result);
      }));
      return;
    }

    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('LeanCloud example app'),
        ),
        body:Column(
//          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            TextField(
              controller: _usernameController,
              autofocus: true,
              decoration: InputDecoration(
                  labelText: "用户名",
                  hintText: "您的用户名",
                  prefixIcon: Icon(Icons.person)),
            ),
            TextField(
              controller: _passwordController,
              decoration: InputDecoration(
                  labelText: "密码",
                  hintText: "您的登录密码",
                  prefixIcon: Icon(Icons.lock)),
              obscureText: true,
            ),
            Text('$_result'),
            RaisedButton(
              child: Text("注册"),
              textColor: Colors.blue,
              onPressed: _signUp,
            ),
            RaisedButton(
              child: Text("登录"),
              textColor: Colors.blue,
              onPressed: _login,
            )
          ],
        ),
      ),
    );
  }
}
0
likes
15
pub points
0%
popularity

Publisher

unverified uploader

LeanCloud Flutter plugin.

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on leancloud