-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5244e74
commit e29c96d
Showing
14 changed files
with
191 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:buzz/buzz.dart'; | ||
import 'package:get/get.dart'; | ||
|
||
import '../../shared/modules/auth/login.dart'; | ||
import '../extensions/get_module.dart'; | ||
|
||
class AuthModuleBuzzRegistry extends BuzzRegistry { | ||
@override | ||
void register(BuzzBase buzz) { | ||
buzz.on<LoginCommand>().listen( | ||
(event) => LoginCommandHandler().handle(event), | ||
); | ||
} | ||
} | ||
|
||
class AuthModule extends GetModule { | ||
@override | ||
List<GetRoute> get routes => [ | ||
LoginRoute(), | ||
]; | ||
} | ||
|
||
class LoginRoute extends GetRoute { | ||
LoginRoute(); | ||
|
||
@override | ||
GetPage get asGetPage => GetPage( | ||
name: LoginPage.routeName, | ||
page: () => const LoginPage(), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:buzz/buzz.dart'; | ||
import 'package:core/core.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:supabase_flutter/supabase_flutter.dart'; | ||
|
||
class LoginPage extends StatelessWidget { | ||
static const String routeName = '/login'; | ||
static const String pageName = 'LoginPage'; | ||
|
||
const LoginPage({ | ||
Key? key, | ||
}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return const BasePage( | ||
name: pageName, | ||
body: LoginView(), | ||
); | ||
} | ||
} | ||
|
||
class LoginView extends StatelessWidget { | ||
const LoginView({ | ||
Key? key, | ||
}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final controller = Get.put(LoginViewController()); | ||
|
||
return Obx(() { | ||
return Column( | ||
children: [ | ||
Padding( | ||
padding: const EdgeInsets.all(16), | ||
child: controller.isLoading() | ||
? const CircularProgressIndicator() | ||
: Text(controller.loginResultString), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.symmetric(horizontal: 15), | ||
child: TextField( | ||
controller: controller.emailTextController, | ||
decoration: const InputDecoration( | ||
border: OutlineInputBorder(), | ||
labelText: 'Email', | ||
hintText: 'Enter valid email id as abc@gmail.com', | ||
), | ||
), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.all(16), | ||
child: MainActionWidget( | ||
action: MainAction( | ||
label: 'Sign In', | ||
onPressed: () => controller.onSignInTap(), | ||
), | ||
), | ||
), | ||
], | ||
); | ||
}); | ||
} | ||
} | ||
|
||
class LoginViewController extends GetxController { | ||
RxBool isLoading = false.obs; | ||
final emailTextController = TextEditingController(); | ||
StreamSubscription? subscription; | ||
Rx<LoginCommandResult?> loginResult = Rxn<LoginCommandResult>(); | ||
|
||
String get loginResultString { | ||
final result = loginResult(); | ||
if (result != null) { | ||
return 'user: ${result.user} – error: ${result.errorMessage}'; | ||
} | ||
|
||
return 'No login result yet'; | ||
} | ||
|
||
@override | ||
void onInit() { | ||
subscription = Buzz.on<LoginCommandResult>().listen(_onLoginCommandResult); | ||
super.onInit(); | ||
} | ||
|
||
void onSignInTap() { | ||
final email = emailTextController.text; | ||
isLoading(true); | ||
Buzz.fire(LoginCommand(email: email)); | ||
} | ||
|
||
@override | ||
void onClose() { | ||
emailTextController.dispose(); | ||
subscription?.cancel(); | ||
subscription = null; | ||
super.onClose(); | ||
} | ||
|
||
void _onLoginCommandResult(LoginCommandResult result) { | ||
isLoading(false); | ||
loginResult(result); | ||
} | ||
} | ||
|
||
class LoginCommand extends Command { | ||
LoginCommand({ | ||
required this.email, | ||
}); | ||
final String email; | ||
} | ||
|
||
class LoginCommandHandler extends CommandHandler<LoginCommand> { | ||
@override | ||
void handle(LoginCommand event) async { | ||
final response = await Supabase.instance.client.auth.signIn( | ||
email: event.email, | ||
); | ||
|
||
final user = response.data?.user; | ||
final error = response.error; | ||
|
||
if (error != null) { | ||
Buzz.fire(LoginCommandResult.failure(error.message)); | ||
return; | ||
} | ||
|
||
//TODO: Avoid leaking data models | ||
Buzz.fire(LoginCommandResult.success(user)); | ||
} | ||
} | ||
|
||
class LoginCommandResult { | ||
final User? user; | ||
final String? errorMessage; | ||
|
||
LoginCommandResult.success(this.user) : errorMessage = null; | ||
LoginCommandResult.failure(this.errorMessage) : user = null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
example/lib/shared/modules/trivia/components/copy_join_link_view.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
example/lib/shared/modules/trivia/components/trivia_data_view.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
example/lib/shared/modules/trivia/finished/trivia_finished_status_view.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
example/lib/shared/modules/trivia/initial/trivia_initial_view.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
example/lib/shared/modules/trivia/started/trivia_started_view.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
library core; | ||
|
||
export 'components/labeled_section.dart'; | ||
export 'components/named_page.dart'; | ||
export 'src/in_memory_store.dart'; | ||
export 'src/json_reader.dart'; | ||
export 'src/managed_stream_builder.dart'; | ||
export 'src/named_page.dart'; |