Skip to content

Commit

Permalink
task: assigning screens to bottomNav
Browse files Browse the repository at this point in the history
  • Loading branch information
Atuoha committed Sep 23, 2022
1 parent 483cfb8 commit f5aaeb4
Show file tree
Hide file tree
Showing 22 changed files with 322 additions and 115 deletions.
5 changes: 5 additions & 0 deletions lib/components/snackbar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

import 'package:flutter/material.dart';
import '../constants/colors.dart';


117 changes: 117 additions & 0 deletions lib/controllers/image_picker.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';

import '../constants/colors.dart';

class ProfileImagePicker extends StatefulWidget {
const ProfileImagePicker({Key? key, required this.selectImage})
: super(key: key);
final Function(File) selectImage;

@override
State<ProfileImagePicker> createState() => _ProfileImagePickerState();
}

// for photo selection
enum Source { camera, gallery }

class _ProfileImagePickerState extends State<ProfileImagePicker> {
XFile? profileImage;
final ImagePicker _picker = ImagePicker();

// for selecting photo
Future _selectPhoto(Source source) async {
XFile? pickedImage;
switch (source) {
case Source.camera:
pickedImage = await _picker.pickImage(
source: ImageSource.camera,
maxWidth: 600,
maxHeight: 600,
);
break;
case Source.gallery:
pickedImage = await _picker.pickImage(
source: ImageSource.gallery,
maxWidth: 600,
maxHeight: 600,
);
break;
}
if (pickedImage == null) {
return null;
}

widget.selectImage(File(pickedImage.path));

// assign the picked image to the profileImage
setState(() {
profileImage = pickedImage;
});
}

// widget for each profile image selector
Widget kContainer(Source source) {
return GestureDetector(
onTap: () => _selectPhoto(source),
child: Container(
height: 40,
width: 40,
decoration: BoxDecoration(
color: primaryColor,
borderRadius: source == Source.gallery
? const BorderRadius.only(
bottomLeft: Radius.circular(20),
bottomRight: Radius.circular(20),
)
: const BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
),
child: Center(
child: Icon(
source == Source.gallery ? Icons.photo : Icons.camera_alt_rounded,
color: Colors.white,
),
),
),
);
}

@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircleAvatar(
radius: profileImage == null ? 60 : 80,
backgroundColor: Colors.white,
child: Center(
child: profileImage == null
? Image.asset(
'assets/images/profile.png',
color: primaryColor,
)
: ClipRRect(
borderRadius: BorderRadius.circular(30),
child: Image.file(
File(profileImage!.path),
),
),
),
),
const SizedBox(width: 5),
Column(
children: [
kContainer(Source.gallery),
const SizedBox(height: 5),
kContainer(Source.camera)
],
)
],
);
}
}
4 changes: 3 additions & 1 deletion lib/controllers/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:multivendor_shop/views/auth/customer_auth.dart';
import 'package:multivendor_shop/views/auth/forgot_password.dart';

import '../views/auth/account_type_selector.dart';
import '../views/main/bottomNav.dart';
import '../views/splash/entry.dart';
import '../views/splash/splash.dart';

Expand All @@ -10,5 +11,6 @@ var routes = {
ForgotPassword.routeName: (context) => const ForgotPassword(),
AccountTypeSelector.routeName: (context) => const AccountTypeSelector(),
SplashScreen.routeName:(context)=>const SplashScreen(),
EntryScreen.routeName:(context)=> const EntryScreen()
EntryScreen.routeName:(context)=> const EntryScreen(),
BottomNav.routeName:(context)=>const BottomNav()
};
145 changes: 37 additions & 108 deletions lib/views/auth/customer_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import 'package:google_sign_in/google_sign_in.dart';
import 'package:image_picker/image_picker.dart';
import 'package:multivendor_shop/views/auth/forgot_password.dart';
import '../../components/loading.dart';
import '../../components/snackbar.dart';
import '../../constants/colors.dart';
import '../../controllers/image_picker.dart';
import '../main/bottomNav.dart';

// for fields
enum Field {
Expand Down Expand Up @@ -38,8 +41,7 @@ class _CustomerAuthState extends State<CustomerAuth> {
final _passwordController = TextEditingController();
var obscure = true; // password obscure value
var isLogin = true;
XFile? profileImage;
final ImagePicker _picker = ImagePicker(); // init imagePicker
File? profileImage;
var isLoading = false;
final _auth = FirebaseAuth.instance;
final firebase = FirebaseFirestore.instance;
Expand All @@ -51,6 +53,26 @@ class _CustomerAuthState extends State<CustomerAuth> {
});
}

// snackbar for error message
showSnackBar(String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
message,
style: const TextStyle(
color: Colors.white,
),
),
backgroundColor: primaryColor,
action: SnackBarAction(
onPressed: () => Navigator.of(context).pop(),
label: 'Dismiss',
textColor: Colors.white,
),
),
);
}

// custom textfield for all form fields
Widget kTextField(
TextEditingController controller,
Expand Down Expand Up @@ -127,85 +149,20 @@ class _CustomerAuthState extends State<CustomerAuth> {
}

// for selecting photo
Future _selectPhoto(Source source) async {
XFile? pickedImage;
switch (source) {
case Source.camera:
pickedImage = await _picker.pickImage(
source: ImageSource.camera, maxWidth: 600, maxHeight: 600);
break;
case Source.gallery:
pickedImage = await _picker.pickImage(
source: ImageSource.gallery, maxWidth: 600, maxHeight: 600);
break;
}
if (pickedImage == null) {
return null;
}

// assign the picked image to the profileImage
_selectPhoto(File image) {
setState(() {
profileImage = pickedImage;
profileImage = image;
});
}

// widget for each profile image selector
Widget kContainer(Source source) {
return GestureDetector(
onTap: () => _selectPhoto(source),
child: Container(
height: 40,
width: 40,
decoration: BoxDecoration(
color: primaryColor,
borderRadius: source == Source.gallery
? const BorderRadius.only(
bottomLeft: Radius.circular(20),
bottomRight: Radius.circular(20),
)
: const BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
),
child: Center(
child: Icon(
source == Source.gallery ? Icons.photo : Icons.camera_alt_rounded,
color: Colors.white,
),
),
),
);
}

// snackbar for error message
void showSnackBar(String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
message,
style: const TextStyle(
color: Colors.white,
),
),
backgroundColor: primaryColor,
action: SnackBarAction(
onPressed: () => Navigator.of(context).pop(),
label: 'Dismiss',
textColor: Colors.white,
),
),
);
}

// loading fnc
isLoadingFnc() {
setState(() {
isLoading = true;
});
// Timer(const Duration(seconds: 5), () {
// Navigator.of(context).pushNamed('');
// });
Timer(const Duration(seconds: 5), () {
Navigator.of(context).pushNamed(BottomNav.routeName);
});
}

// handle sign in and sign up
Expand All @@ -224,6 +181,7 @@ class _CustomerAuthState extends State<CustomerAuth> {
email: _emailController.text.trim(),
password: _passwordController.text.trim(),
);
isLoadingFnc(); // spin and redirect
} else {
// TODO: implement sign up

Expand Down Expand Up @@ -256,7 +214,9 @@ class _CustomerAuthState extends State<CustomerAuth> {
});
isLoadingFnc();
} catch (e) {
showSnackBar('An error occurred with image uploading');
if (kDebugMode) {
showSnackBar('An error occurred with image uploading');
}
if (kDebugMode) {
print('AN ERROR OCCURRED! $e');
}
Expand Down Expand Up @@ -319,9 +279,7 @@ class _CustomerAuthState extends State<CustomerAuth> {
'auth-type': 'google',
},
).then((value) {
// isLoadingFnc();
// update authtype
// Provider.of<SongData>(context).updateAuthType();
isLoadingFnc();
});
} on FirebaseAuthException catch (e) {
var error = 'An error occurred. Check credentials!';
Expand All @@ -337,7 +295,7 @@ class _CustomerAuthState extends State<CustomerAuth> {
print(e);
}
}
// sign in with credential
// sign in with credential
return FirebaseAuth.instance.signInWithCredential(credential);
}

Expand Down Expand Up @@ -384,36 +342,7 @@ class _CustomerAuthState extends State<CustomerAuth> {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
!isLogin
? Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircleAvatar(
radius: profileImage == null ? 60 : 80,
backgroundColor: Colors.white,
child: Center(
child: profileImage == null
? Image.asset(
'assets/images/profile.png',
color: primaryColor,
)
: ClipRRect(
borderRadius: BorderRadius.circular(30),
child: Image.file(
File(profileImage!.path),
),
),
),
),
const SizedBox(width: 5),
Column(
children: [
kContainer(Source.gallery),
const SizedBox(height: 5),
kContainer(Source.camera)
],
)
],
)
? ProfileImagePicker(selectImage: _selectPhoto)
: const SizedBox.shrink(),
const SizedBox(height: 20),
Center(
Expand All @@ -431,7 +360,7 @@ class _CustomerAuthState extends State<CustomerAuth> {
? const Center(
child: Loading(
color: primaryColor,
kSize: 100,
kSize: 70,
),
)
: Form(
Expand Down
Loading

0 comments on commit f5aaeb4

Please sign in to comment.