#8 Register with Email & password

Download files

#8.1 Upload img to screen (Mobile & Web)

1-
import 'dart:typed_data';
 
Uint8List? imgPath;
String? imgName;
2-
uploadImage2Screen(ImageSource source) async {
 Navigator.pop(context);
 final XFile? pickedImg = await ImagePicker().pickImage(source: source);
  try {
      if (pickedImg != null) {
      imgPath = await pickedImg.readAsBytes();
      setState(() {
      imgName = basename(pickedImg.path);
      int random = Random().nextInt(9999999);
      imgName = "$random$imgName";
      print(imgName);
   });
 } else {
   print("NO img selected");
   }
 } catch (e) {
  print("Error => $e");
   }}
3-
CircleAvatar(
  radius: 71,
  backgroundImage: MemoryImage(imgPath!),
 ),

Download files

#8.2 Send data to Firestore Database

Download files

#8.3 Send data to Firestore Database طريقة المشاريع الكبيرة

1- model > user.dart
 class UserDate {
   String username;
 
   UserDate({required this.username,});
 
  // To convert the UserData(Data type) to   Map<String, Object>
  Map<String, dynamic> convert2Map() {
  return {"username": username,};
 }
 
2- firebase_services > auth.dart
  UserDate userr = UserDate(username: usernameee);
  
  users.doc(credential.user!.uid).set(userr.convert2Map())

Download files

#8.4 Upload img to storage & Get img url

👉 firebase_services > storage.dart
 // Function to get img url
 
getImgURL({
 required String imgName,
 required Uint8List imgPath,
 }) async {
 // Upload image to firebase storage
   final storageRef = FirebaseStorage.instance.ref("FOLDERNAME/$imgName");
 // use this code if u are using flutter web
 UploadTask uploadTask = storageRef.putData(imgPath);
 TaskSnapshot snap = await uploadTask;
 
 // Get img url
 String urll = await snap.ref.getDownloadURL();
 
 return urll;
 }

Download files

#8.5 Finish Register Screen

Download files

😡
انت مشغل الـ AdBlock !!

ياريت تقفله لوسمحت 😊 😊

تنبيه هام ✋

إذا كانت الإعلانات مزعجة بالنسبة لك، فيُمكنك التبرع ب50$ وسيتم إيقاف الإعلانات لمدة شهر لجميع زوار الموقع 🧡 ويُمكنك التواصل معنا عن طريق صفحة الفيس بوك