diff --git a/lib/features/auth/view/widgets/auth_view_body.dart b/lib/features/auth/view/widgets/auth_view_body.dart index 0673a87..eed099b 100644 --- a/lib/features/auth/view/widgets/auth_view_body.dart +++ b/lib/features/auth/view/widgets/auth_view_body.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:syncrow_app/features/shared_widgets/default_text_button.dart'; +import 'package:syncrow_app/features/shared_widgets/default_button.dart'; import 'package:syncrow_app/features/shared_widgets/syncrow_logo.dart'; import '../../../../navigation/routing_constants.dart'; @@ -19,14 +19,14 @@ class AuthViewBody extends StatelessWidget { const Expanded(child: SizedBox()), const SyncrowLogo(), const Expanded(flex: 2, child: SizedBox()), - DefaultTextButton( + DefaultButton( text: 'Login', onPressed: () { Navigator.pushNamed(context, Routes.authLogin); }, ), const SizedBox(height: 15), - const DefaultTextButton( + const DefaultButton( text: 'Sign Up', isSecondary: true, ), diff --git a/lib/features/auth/view/widgets/login/login_button.dart b/lib/features/auth/view/widgets/login/login_button.dart new file mode 100644 index 0000000..1962c12 --- /dev/null +++ b/lib/features/auth/view/widgets/login/login_button.dart @@ -0,0 +1,50 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_app/features/auth/bloc/auth_cubit.dart'; +import 'package:syncrow_app/features/shared_widgets/default_button.dart'; + +class LoginButton extends StatelessWidget { + const LoginButton({ + super.key, + }); + + @override + Widget build(BuildContext context) { + return BlocBuilder( + builder: (context, state) { + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded( + child: DefaultButton( + enabled: AuthCubit.get(context).agreeToTerms, + text: state is AuthLoading + ? null + : state is AuthSuccess + ? null + : "Login", + child: state is AuthSuccess + ? const Icon( + Icons.check_circle_outline, + color: Colors.white, + ) + : const SizedBox.square( + dimension: 20, + child: CircularProgressIndicator( + color: Colors.white, + ), + ), + onPressed: () { + if (AuthCubit.get(context).formKey.currentState!.validate()) { + AuthCubit.get(context).login(); + FocusScope.of(context).unfocus(); + } + }, + ), + ), + ], + ); + }, + ); + } +} diff --git a/lib/features/auth/view/widgets/login/login_view.dart b/lib/features/auth/view/widgets/login/login_view.dart index 7ef4010..6850935 100644 --- a/lib/features/auth/view/widgets/login/login_view.dart +++ b/lib/features/auth/view/widgets/login/login_view.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/auth/bloc/auth_cubit.dart'; +import 'package:syncrow_app/features/auth/view/widgets/login/login_button.dart'; import 'package:syncrow_app/features/auth/view/widgets/login/login_form.dart'; import 'package:syncrow_app/features/auth/view/widgets/login/login_user_agreement.dart'; -import 'package:syncrow_app/features/shared_widgets/default_text_button.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.dart'; import 'package:syncrow_app/navigation/routing_constants.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart'; @@ -30,46 +30,25 @@ class LoginView extends StatelessWidget { builder: (context, state) { return Scaffold( appBar: AppBar(), - body: Padding( - padding: const EdgeInsets.symmetric( + body: const Padding( + padding: EdgeInsets.symmetric( horizontal: Constants.defaultPadding, ), child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [ - const TitleMedium( + TitleMedium( text: 'Login', ), - const SizedBox( + SizedBox( height: 10, ), - const LoginForm(), - const SizedBox(height: 10), - const LoginUserAgreement(), - const SizedBox(height: 10), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - state is AuthLoading - ? const CircularProgressIndicator() - : Expanded( - child: DefaultTextButton( - enabled: AuthCubit.get(context).agreeToTerms, - text: "Login", - onPressed: () { - if (AuthCubit.get(context) - .formKey - .currentState! - .validate()) { - AuthCubit.get(context).login(); - FocusScope.of(context).unfocus(); - } - }, - ), - ), - ], - ), + LoginForm(), + SizedBox(height: 10), + LoginUserAgreement(), + SizedBox(height: 10), + LoginButton(), ], ), ), diff --git a/lib/features/devices/view/widgets/no_devices_view.dart b/lib/features/devices/view/widgets/no_devices_view.dart index 27b9029..c509579 100644 --- a/lib/features/devices/view/widgets/no_devices_view.dart +++ b/lib/features/devices/view/widgets/no_devices_view.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:syncrow_app/features/shared_widgets/default_text_button.dart'; +import 'package:syncrow_app/features/shared_widgets/default_button.dart'; import 'package:syncrow_app/generated/assets.dart'; class NoDevicesView extends StatelessWidget { @@ -28,7 +28,7 @@ class NoDevicesView extends StatelessWidget { ), ), const SizedBox(height: 15), - const DefaultTextButton( + const DefaultButton( text: 'Add Device', ), ], diff --git a/lib/features/scene/view/widgets/scene_view_no_scenes.dart b/lib/features/scene/view/widgets/scene_view_no_scenes.dart index 2c884ea..841327b 100644 --- a/lib/features/scene/view/widgets/scene_view_no_scenes.dart +++ b/lib/features/scene/view/widgets/scene_view_no_scenes.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:syncrow_app/features/shared_widgets/default_text_button.dart'; +import 'package:syncrow_app/features/shared_widgets/default_button.dart'; import 'package:syncrow_app/generated/assets.dart'; class SceneViewNoScenes extends StatelessWidget { @@ -28,7 +28,7 @@ class SceneViewNoScenes extends StatelessWidget { style: TextStyle(color: Colors.grey), ), const SizedBox(height: 20), - const DefaultTextButton( + const DefaultButton( text: 'Create Scene', ) ], diff --git a/lib/features/shared_widgets/default_text_button.dart b/lib/features/shared_widgets/default_button.dart similarity index 61% rename from lib/features/shared_widgets/default_text_button.dart rename to lib/features/shared_widgets/default_button.dart index db6bf49..ed3e29f 100644 --- a/lib/features/shared_widgets/default_text_button.dart +++ b/lib/features/shared_widgets/default_button.dart @@ -1,24 +1,27 @@ import 'package:flutter/material.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; -class DefaultTextButton extends StatelessWidget { - const DefaultTextButton({ +class DefaultButton extends StatelessWidget { + const DefaultButton({ super.key, this.enabled = true, this.onPressed, - required this.text, + this.child, this.isSecondary = false, + this.text, }); final void Function()? onPressed; - final String text; + final Widget? child; + + final String? text; final bool isSecondary; final bool enabled; @override Widget build(BuildContext context) { - return TextButton( + return ElevatedButton( onPressed: enabled ? onPressed : null, style: isSecondary ? null @@ -31,15 +34,18 @@ class DefaultTextButton extends StatelessWidget { ), ), ), - child: Text( - text, - style: TextStyle( - color: isSecondary - ? Colors.black - : enabled - ? Colors.white - : Colors.black), - ), + child: text != null + ? Text( + text!, + style: TextStyle( + color: isSecondary + ? Colors.black + : enabled + ? Colors.white + : Colors.black, + ), + ) + : child, ); } } diff --git a/lib/features/splash/view/widgets/user_agreement_dialog.dart b/lib/features/splash/view/widgets/user_agreement_dialog.dart index a4c3dfc..a60d907 100644 --- a/lib/features/splash/view/widgets/user_agreement_dialog.dart +++ b/lib/features/splash/view/widgets/user_agreement_dialog.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:syncrow_app/features/shared_widgets/default_text_button.dart'; +import 'package:syncrow_app/features/shared_widgets/default_button.dart'; class UserAgreementDialog extends StatelessWidget { const UserAgreementDialog({ @@ -14,13 +14,13 @@ class UserAgreementDialog extends StatelessWidget { content: const Text('By using this app you agree to the terms and conditions'), actions: [ - DefaultTextButton( + DefaultButton( text: 'I Agree', onPressed: () { Navigator.of(context).pop(); }, ), - DefaultTextButton( + DefaultButton( text: 'I Disagree', onPressed: () => Navigator.of(context).pop(), isSecondary: true,