bloc
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:prosappco/blocs/sing_in_bloc/sign_in_bloc.dart';
|
||||
|
||||
import '../../components/strings.dart';
|
||||
import '../../components/textfield.dart';
|
||||
|
||||
class SignInScreen extends StatefulWidget {
|
||||
const SignInScreen({super.key});
|
||||
|
||||
@override
|
||||
State<SignInScreen> createState() => _SignInScreenState();
|
||||
}
|
||||
|
||||
class _SignInScreenState extends State<SignInScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final emailController = TextEditingController();
|
||||
final passwordController = TextEditingController();
|
||||
String? _errorMsg;
|
||||
bool obscurePassword = true;
|
||||
IconData iconPassword = CupertinoIcons.eye_fill;
|
||||
bool signInRequired = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<SignInBloc, SignInState>(
|
||||
listener: (context, state) {
|
||||
if (state is SignInSuccess) {
|
||||
setState(() {
|
||||
signInRequired = false;
|
||||
});
|
||||
} else if (state is SignInProcess) {
|
||||
setState(() {
|
||||
signInRequired = true;
|
||||
});
|
||||
} else if (state is SignInFailure) {
|
||||
setState(() {
|
||||
signInRequired = false;
|
||||
_errorMsg = 'Invalid email or password';
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.9,
|
||||
child: MyTextField(
|
||||
controller: emailController,
|
||||
hintText: 'Email',
|
||||
obscureText: false,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
prefixIcon: const Icon(CupertinoIcons.mail_solid),
|
||||
errorMsg: _errorMsg,
|
||||
validator: (val) {
|
||||
if (val!.isEmpty) {
|
||||
return 'Please fill in this field';
|
||||
} else if (!emailRexExp.hasMatch(val)) {
|
||||
return 'Please enter a valid email';
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.9,
|
||||
child: MyTextField(
|
||||
controller: passwordController,
|
||||
hintText: 'Password',
|
||||
obscureText: obscurePassword,
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
prefixIcon: const Icon(CupertinoIcons.lock_fill),
|
||||
errorMsg: _errorMsg,
|
||||
validator: (val) {
|
||||
if (val!.isEmpty) {
|
||||
return 'Please fill in this field';
|
||||
} else if (!passwordRexExp.hasMatch(val)) {
|
||||
return 'Please enter a valid password';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
suffixIcon: IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
obscurePassword = !obscurePassword;
|
||||
if (obscurePassword) {
|
||||
iconPassword = CupertinoIcons.eye_fill;
|
||||
} else {
|
||||
iconPassword = CupertinoIcons.eye_slash_fill;
|
||||
}
|
||||
});
|
||||
},
|
||||
icon: Icon(iconPassword),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
!signInRequired
|
||||
? SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.9,
|
||||
height: 50,
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
context.read<SignInBloc>().add(SignInRequired(
|
||||
emailController.text,
|
||||
passwordController.text));
|
||||
}
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
elevation: 3.0,
|
||||
backgroundColor:
|
||||
Theme.of(context).colorScheme.primary,
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(60))),
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 25, vertical: 5),
|
||||
child: Text(
|
||||
'Sign In',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600),
|
||||
),
|
||||
)),
|
||||
)
|
||||
: const CircularProgressIndicator()
|
||||
],
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
|
||||
import '../../blocs/sign_up_bloc/sign_up_bloc.dart';
|
||||
import '../../components/strings.dart';
|
||||
import '../../components/textfield.dart';
|
||||
|
||||
class SignUpScreen extends StatefulWidget {
|
||||
const SignUpScreen({super.key});
|
||||
|
||||
@override
|
||||
State<SignUpScreen> createState() => _SignUpScreenState();
|
||||
}
|
||||
|
||||
class _SignUpScreenState extends State<SignUpScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final emailController = TextEditingController();
|
||||
final passwordController = TextEditingController();
|
||||
bool obscurePassword = true;
|
||||
IconData iconPassword = CupertinoIcons.eye_fill;
|
||||
final nameController = TextEditingController();
|
||||
bool signUpRequired = false;
|
||||
|
||||
bool containsUpperCase = false;
|
||||
bool containsLowerCase = false;
|
||||
bool containsNumber = false;
|
||||
bool containsSpecialChar = false;
|
||||
bool contains8Length = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<SignUpBloc, SignUpState>(
|
||||
listener: (context, state) {
|
||||
if (state is SignUpSuccess) {
|
||||
setState(() {
|
||||
signUpRequired = false;
|
||||
});
|
||||
} else if (state is SignUpProcess) {
|
||||
setState(() {
|
||||
signUpRequired = true;
|
||||
});
|
||||
} else if (state is SignUpFailure) {
|
||||
return;
|
||||
}
|
||||
},
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.9,
|
||||
child: MyTextField(
|
||||
controller: emailController,
|
||||
hintText: 'Email',
|
||||
obscureText: false,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
prefixIcon: const Icon(CupertinoIcons.mail_solid),
|
||||
validator: (val) {
|
||||
if (val!.isEmpty) {
|
||||
return 'Please fill in this field';
|
||||
} else if (!emailRexExp.hasMatch(val)) {
|
||||
return 'Please enter a valid email';
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.9,
|
||||
child: MyTextField(
|
||||
controller: passwordController,
|
||||
hintText: 'Password',
|
||||
obscureText: obscurePassword,
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
prefixIcon: const Icon(CupertinoIcons.lock_fill),
|
||||
onChanged: (val) {
|
||||
if (val!.contains(RegExp(r'[A-Z]'))) {
|
||||
setState(() {
|
||||
containsUpperCase = true;
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
containsUpperCase = false;
|
||||
});
|
||||
}
|
||||
if (val.contains(RegExp(r'[a-z]'))) {
|
||||
setState(() {
|
||||
containsLowerCase = true;
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
containsLowerCase = false;
|
||||
});
|
||||
}
|
||||
if (val.contains(RegExp(r'[0-9]'))) {
|
||||
setState(() {
|
||||
containsNumber = true;
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
containsNumber = false;
|
||||
});
|
||||
}
|
||||
if (val.contains(specialCharRexExp)) {
|
||||
setState(() {
|
||||
containsSpecialChar = true;
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
containsSpecialChar = false;
|
||||
});
|
||||
}
|
||||
if (val.length >= 8) {
|
||||
setState(() {
|
||||
contains8Length = true;
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
contains8Length = false;
|
||||
});
|
||||
}
|
||||
return null;
|
||||
},
|
||||
suffixIcon: IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
obscurePassword = !obscurePassword;
|
||||
if (obscurePassword) {
|
||||
iconPassword = CupertinoIcons.eye_fill;
|
||||
} else {
|
||||
iconPassword = CupertinoIcons.eye_slash_fill;
|
||||
}
|
||||
});
|
||||
},
|
||||
icon: Icon(iconPassword),
|
||||
),
|
||||
validator: (val) {
|
||||
if (val!.isEmpty) {
|
||||
return 'Please fill in this field';
|
||||
} else if (!passwordRexExp.hasMatch(val)) {
|
||||
return 'Please enter a valid password';
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"⚈ 1 uppercase",
|
||||
style: TextStyle(
|
||||
color: containsUpperCase
|
||||
? Colors.green
|
||||
: Theme.of(context).colorScheme.onBackground),
|
||||
),
|
||||
Text(
|
||||
"⚈ 1 lowercase",
|
||||
style: TextStyle(
|
||||
color: containsLowerCase
|
||||
? Colors.green
|
||||
: Theme.of(context).colorScheme.onBackground),
|
||||
),
|
||||
Text(
|
||||
"⚈ 1 number",
|
||||
style: TextStyle(
|
||||
color: containsNumber
|
||||
? Colors.green
|
||||
: Theme.of(context).colorScheme.onBackground),
|
||||
),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"⚈ 1 special character",
|
||||
style: TextStyle(
|
||||
color: containsSpecialChar
|
||||
? Colors.green
|
||||
: Theme.of(context).colorScheme.onBackground),
|
||||
),
|
||||
Text(
|
||||
"⚈ 8 minimum character",
|
||||
style: TextStyle(
|
||||
color: contains8Length
|
||||
? Colors.green
|
||||
: Theme.of(context).colorScheme.onBackground),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.9,
|
||||
child: MyTextField(
|
||||
controller: nameController,
|
||||
hintText: 'Name',
|
||||
obscureText: false,
|
||||
keyboardType: TextInputType.name,
|
||||
prefixIcon: const Icon(CupertinoIcons.person_fill),
|
||||
validator: (val) {
|
||||
if (val!.isEmpty) {
|
||||
return 'Please fill in this field';
|
||||
} else if (val.length > 30) {
|
||||
return 'Name too long';
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
),
|
||||
SizedBox(height: MediaQuery.of(context).size.height * 0.02),
|
||||
!signUpRequired
|
||||
? SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.5,
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
MyUser myUser = MyUser.empty;
|
||||
myUser = myUser.copyWith(
|
||||
email: emailController.text,
|
||||
name: nameController.text,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
context.read<SignUpBloc>().add(SignUpRequired(
|
||||
myUser, passwordController.text));
|
||||
});
|
||||
}
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
elevation: 3.0,
|
||||
backgroundColor:
|
||||
Theme.of(context).colorScheme.primary,
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(60))),
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 25, vertical: 5),
|
||||
child: Text(
|
||||
'Sign Up',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600),
|
||||
),
|
||||
)),
|
||||
)
|
||||
: const CircularProgressIndicator()
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:prosappco/blocs/sing_in_bloc/sign_in_bloc.dart';
|
||||
import 'package:prosappco/screens/authentication/sign_in_screen.dart';
|
||||
import 'package:prosappco/screens/authentication/sign_up_screen.dart';
|
||||
|
||||
import '../../blocs/authentication_bloc/authentication_bloc.dart';
|
||||
import '../../blocs/sign_up_bloc/sign_up_bloc.dart';
|
||||
|
||||
class WelcomeScreen extends StatefulWidget {
|
||||
const WelcomeScreen({super.key});
|
||||
|
||||
@override
|
||||
State<WelcomeScreen> createState() => _WelcomeScreenState();
|
||||
}
|
||||
|
||||
class _WelcomeScreenState extends State<WelcomeScreen>
|
||||
with TickerProviderStateMixin {
|
||||
late TabController tabController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
tabController = TabController(
|
||||
initialIndex: 0,
|
||||
length: 2,
|
||||
vsync: this,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
appBar: AppBar(
|
||||
elevation: 0,
|
||||
backgroundColor: Colors.transparent,
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: SizedBox(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Column(
|
||||
children: [
|
||||
const Text(
|
||||
'Welcome Back !',
|
||||
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: kToolbarHeight),
|
||||
TabBar(
|
||||
controller: tabController,
|
||||
unselectedLabelColor: Theme.of(context)
|
||||
.colorScheme
|
||||
.onBackground
|
||||
.withOpacity(0.5),
|
||||
labelColor: Theme.of(context).colorScheme.onBackground,
|
||||
tabs: const [
|
||||
Padding(
|
||||
padding: EdgeInsets.all(12.0),
|
||||
child: Text(
|
||||
'Sign In',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.all(12.0),
|
||||
child: Text(
|
||||
'Sign Up',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
Expanded(
|
||||
child: TabBarView(controller: tabController, children: [
|
||||
BlocProvider<SignInBloc>(
|
||||
create: (context) => SignInBloc(
|
||||
userRepository: context
|
||||
.read<AuthenticationBloc>()
|
||||
.userRepository),
|
||||
child: const SignInScreen(),
|
||||
),
|
||||
BlocProvider<SignUpBloc>(
|
||||
create: (context) => SignUpBloc(
|
||||
userRepository: context
|
||||
.read<AuthenticationBloc>()
|
||||
.userRepository),
|
||||
child: const SignUpScreen(),
|
||||
),
|
||||
]),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart';
|
||||
import 'package:prosappco/blocs/sing_in_bloc/sign_in_bloc.dart';
|
||||
import 'package:prosappco/blocs/update_user_info_bloc/update_user_info_bloc.dart';
|
||||
import 'package:prosappco/screens/profile/profile_screen.dart';
|
||||
|
||||
class HomeScreen extends StatefulWidget {
|
||||
const HomeScreen({super.key});
|
||||
|
||||
@override
|
||||
State<HomeScreen> createState() => _HomeScreenState();
|
||||
}
|
||||
|
||||
class _HomeScreenState extends State<HomeScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<UpdateUserInfoBloc, UpdateUserInfoState>(
|
||||
listener: (context, state) {
|
||||
if (state is UploadPictureSuccess) {
|
||||
setState(() {
|
||||
context.read<MyUserBloc>().state.user!.picture = state.userImage;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
drawer: BlocBuilder<MyUserBloc, MyUserState>(builder: (context, state) {
|
||||
if (state.status == MyUserStatus.success) {
|
||||
return Drawer(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Material(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => const ProfileScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(
|
||||
top: 20 + MediaQuery.of(context).padding.top,
|
||||
bottom: 20,
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
state.user!.picture == ""
|
||||
? Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade300,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
CupertinoIcons.person,
|
||||
color: Colors.grey.shade400,
|
||||
size: 35,
|
||||
),
|
||||
)
|
||||
: Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey,
|
||||
shape: BoxShape.circle,
|
||||
image: DecorationImage(
|
||||
image: NetworkImage(
|
||||
state.user!.picture!,
|
||||
),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
context.read<MyUserBloc>().state.user!.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
state.user!.email,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
color: Theme.of(context).colorScheme.background,
|
||||
child: ListView(
|
||||
children: [
|
||||
ListTile(
|
||||
onTap: () {
|
||||
context
|
||||
.read<SignInBloc>()
|
||||
.add(const SignOutRequired());
|
||||
},
|
||||
title: const Text(
|
||||
'Cerrar Sesión',
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Drawer(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
));
|
||||
}
|
||||
}),
|
||||
appBar: AppBar(),
|
||||
body: const Placeholder(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:prosappco/blocs/authentication_bloc/authentication_bloc.dart';
|
||||
import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart';
|
||||
import 'package:prosappco/blocs/update_user_info_bloc/update_user_info_bloc.dart';
|
||||
import 'package:prosappco/src/components/pop_appbar.dart';
|
||||
|
||||
class ProfileScreen extends StatefulWidget {
|
||||
const ProfileScreen({super.key});
|
||||
|
||||
@override
|
||||
State<ProfileScreen> createState() => _ProfileScreenState();
|
||||
}
|
||||
|
||||
class _ProfileScreenState extends State<ProfileScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(
|
||||
create: (context) => MyUserBloc(
|
||||
myUserRepository:
|
||||
context.read<AuthenticationBloc>().userRepository)
|
||||
..add(GetMyUser(
|
||||
myUserId: context.read<AuthenticationBloc>().state.user!.uid)),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (context) => UpdateUserInfoBloc(
|
||||
userRepository: context.read<AuthenticationBloc>().userRepository,
|
||||
),
|
||||
)
|
||||
],
|
||||
child: BlocListener<UpdateUserInfoBloc, UpdateUserInfoState>(
|
||||
listener: (context, state) {
|
||||
if (state is UploadPictureSuccess) {
|
||||
setState(() {
|
||||
context.read<MyUserBloc>().state.user!.picture = state.userImage;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: PopAppbar(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
label: 'Perfil',
|
||||
),
|
||||
body:
|
||||
BlocBuilder<MyUserBloc, MyUserState>(builder: (context, state) {
|
||||
if (state.status == MyUserStatus.success) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
final ImagePicker picker = ImagePicker();
|
||||
final XFile? image = await picker.pickImage(
|
||||
source: ImageSource.gallery,
|
||||
maxHeight: 500,
|
||||
maxWidth: 500,
|
||||
imageQuality: 40,
|
||||
);
|
||||
|
||||
if (image != null) {
|
||||
context.read<UpdateUserInfoBloc>().add(
|
||||
UploadPicture(image.path, state.user!.id),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: state.user!.picture == ""
|
||||
? Container(
|
||||
width: 120,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade300,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
CupertinoIcons.person,
|
||||
color: Colors.grey.shade400,
|
||||
size: 40,
|
||||
),
|
||||
)
|
||||
: Container(
|
||||
width: 120,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey,
|
||||
shape: BoxShape.circle,
|
||||
image: DecorationImage(
|
||||
image: NetworkImage(
|
||||
state.user!.picture!,
|
||||
),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20.0),
|
||||
TextFormField(
|
||||
initialValue: state.user?.name,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Nombre',
|
||||
prefixIcon: Icon(Icons.person),
|
||||
hintText: 'Nombre (obligatorio)',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(25.0),
|
||||
)),
|
||||
errorBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.red),
|
||||
),
|
||||
focusedErrorBorder: OutlineInputBorder(
|
||||
borderSide:
|
||||
BorderSide(color: Colors.red, width: 2.0),
|
||||
),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Por favor, ingrese su nombre';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20.0),
|
||||
TextFormField(
|
||||
initialValue: state.user?.email,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Nombre',
|
||||
prefixIcon: Icon(Icons.person),
|
||||
hintText: 'Nombre (obligatorio)',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(25.0),
|
||||
)),
|
||||
errorBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.red),
|
||||
),
|
||||
focusedErrorBorder: OutlineInputBorder(
|
||||
borderSide:
|
||||
BorderSide(color: Colors.red, width: 2.0),
|
||||
),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Por favor, ingrese su nombre';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {},
|
||||
child: const Text('Guardar'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
})),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user