@@ -27,20 +27,6 @@ class _MyAppState extends State<MyApp> {
2727 );
2828
2929 final Future <Parse > initFuture;
30- bool loggedIn = false ;
31-
32- @override
33- void initState () {
34- super .initState ();
35-
36- initFuture.then ((_) async {
37- final ParseUser currentUser = await ParseUser .currentUser ();
38- setState (() {
39- loggedIn = currentUser != null ;
40- print (loggedIn);
41- });
42- });
43- }
4430
4531 @override
4632 Widget build (BuildContext context) {
@@ -50,24 +36,7 @@ class _MyAppState extends State<MyApp> {
5036 future: initFuture,
5137 builder: (BuildContext context, AsyncSnapshot <Parse > snapshot) {
5238 if (snapshot.hasData) {
53- if (! loggedIn) {
54- return MyLoginPage (
55- title: 'Flutter Demo Home Page' ,
56- afterLogin: () {
57- setState (() {
58- loggedIn = true ;
59- });
60- },
61- );
62- } else {
63- return HelloPage (
64- afterLogout: () {
65- setState (() {
66- loggedIn = false ;
67- });
68- },
69- );
70- }
39+ return MyLoginPage (title: 'Flutter Demo Home Page' );
7140 } else {
7241 return const Scaffold (
7342 body: Center (
@@ -81,70 +50,76 @@ class _MyAppState extends State<MyApp> {
8150 }
8251}
8352
84- class HelloPage extends StatelessWidget {
85- final VoidCallback afterLogout;
86-
87- const HelloPage ({Key key, @required this .afterLogout}) : super (key: key);
88-
89- @override
90- Widget build (BuildContext context) {
91- return Scaffold (
92- appBar: AppBar (
93- title: const Text ('Welcome!' ),
94- ),
95- body: Center (
96- child: Column (
97- mainAxisAlignment: MainAxisAlignment .center,
98- crossAxisAlignment: CrossAxisAlignment .center,
99- children: < Widget > [
100- const Text ('You are logged in!' ),
101- OutlineButton (
102- onPressed: () async {
103- (await ParseUser .currentUser () as ParseUser )
104- ? .logout ()
105- ? .then ((ParseResponse response) {
106- if (response.success) {
107- afterLogout ();
108- }
109- });
110- },
111- child: const Text ('logout' ),
112- ),
113- ],
114- ),
115- ),
116- );
117- }
118- }
119-
12053class MyLoginPage extends StatelessWidget {
121- MyLoginPage ({Key key, this .title, @required this .afterLogin })
54+ MyLoginPage ({Key key, this .title})
12255 : _rnd = Random (),
12356 super (key: key);
12457
12558 final String title;
126- final VoidCallback afterLogin;
12759
12860 @override
12961 Widget build (BuildContext context) {
13062 return Scaffold (
13163 appBar: AppBar (
13264 title: Text (title),
13365 ),
134- body: Center (
135- child: OutlineButton (
136- onPressed: () async {
137- final String email = '${getRandomString (10 )}@example.com' ;
138- final ParseResponse response =
139- await ParseUser (email, getRandomString (10 ), email).signUp ();
140- print (
141- 'Sign up was ${!(response ?.success ?? false ) ? 'not ' : '' }success full. Response is ${response == null ? '' : 'not ' }null.' );
142- if (response.success) {
143- afterLogin ();
144- }
145- },
146- child: Text ("sign up" ),
147- ),
66+ body: Column (
67+ children: [
68+ OutlineButton (
69+ onPressed: () async {
70+ signUp (
71+ username: getRandomString (10 ),
72+ pass: getRandomString (10 ),
73+ email: "${getRandomString (10 )}@example.com" );
74+ // final ParseUser user = ParseUser(getRandomString(10),
75+ // getRandomString(10), "${getRandomString(10)}@example.com");
76+ // print('method signIn, user is: $user');
77+ //
78+ // final ParseResponse response = await user.signUp();
79+ // print(
80+ // 'auth_service_parse.dart, method signIn, response is: ${response}');
81+ //
82+ // if (response.success) {
83+ // print('user logged in with id: ${user.objectId}');
84+ // return user;
85+ // } else {
86+ // print('user logging in error: ${response.error.message}');
87+ // }
88+ //
89+ // print('user sign in is null');
90+ // return null;
91+ },
92+ child: const Text ("sign up" ),
93+ ),
94+ RaisedButton (
95+ onPressed: () async {
96+ final ParseUser user = ParseUser (
97+ "${getRandomString (10 )}@example.com" ,
98+ getRandomString (10 ),
99+ "${getRandomString (10 )}@example.com" );
100+ print ('method signIn, user is: $user ' );
101+
102+ user.signUp ().then ((singUpResponse) async {
103+ print ('singUpResponse: ${singUpResponse .success }' );
104+
105+ ParseResponse response = await user.login ();
106+ print (
107+ 'auth_service_parse.dart, method signIn, response is: ${response .success }' );
108+
109+ if (response.success) {
110+ print ('user logged in with id: ${user .objectId }' );
111+ return user;
112+ } else {
113+ print ('user logging in error: ${response .error .message }' );
114+ }
115+
116+ print ('user sign in is null' );
117+ return null ;
118+ });
119+ },
120+ child: const Text ("sign up 2" ),
121+ ),
122+ ],
148123 ),
149124 );
150125 }
@@ -157,13 +132,13 @@ class MyLoginPage extends StatelessWidget {
157132 length, (_) => _chars.codeUnitAt (_rnd.nextInt (_chars.length))));
158133
159134 void signUp ({String email, String pass, String username}) async {
160- print (' SignUp started' );
135+ print (" SignUp started" );
161136 ParseUser user = ParseUser .createUser (username, pass, email);
162137 print (user);
163- final ParseResponse response = await user.signUp ();
138+ ParseResponse response = await user.signUp ();
164139 print (response);
165140 if (response.success) {
166- print (' SignUp Success' );
141+ print (" SignUp Success" );
167142 }
168143 }
169144}
0 commit comments