Added loading and success icons to login button

This commit is contained in:
Mohammad Salameh
2024-03-10 10:58:45 +03:00
parent 2c4543e83f
commit ce34933738
7 changed files with 90 additions and 55 deletions

View File

@ -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,
),

View File

@ -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<AuthCubit, AuthState>(
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();
}
},
),
),
],
);
},
);
}
}

View File

@ -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(),
],
),
),

View File

@ -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',
),
],

View File

@ -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',
)
],

View File

@ -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,
child: text != null
? Text(
text!,
style: TextStyle(
color: isSecondary
? Colors.black
: enabled
? Colors.white
: Colors.black),
: Colors.black,
),
)
: child,
);
}
}

View File

@ -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,