Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. import 'package:firebase_auth/firebase_auth.dart';
  2. import 'package:firebase_storage/firebase_storage.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/material.dart';
  5.  
  6. class Helper {
  7. static final FirebaseAuth _auth = FirebaseAuth.instance;
  8. static final TextEditingController _imageName = TextEditingController();
  9.  
  10. static Future<String> getImage(String image) async {
  11. StorageReference ref = FirebaseStorage.instance.ref().child(image);
  12. var url = await ref.getDownloadURL();
  13. return url.toString();
  14. }
  15.  
  16. static bool isEmail(String em) {
  17. String p =
  18. r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
  19.  
  20. RegExp regExp = new RegExp(p);
  21.  
  22. return regExp.hasMatch(em.trim());
  23. }
  24.  
  25. static void showCupertinoDialog(String msg, BuildContext context) {
  26. showDialog(
  27. context: context,
  28. builder: (context) {
  29. return CupertinoAlertDialog(
  30. title: Text('Alert Dialog'),
  31. content: Text('$msg'),
  32. actions: <Widget>[
  33. FlatButton(
  34. onPressed: () {
  35. _dismissDialog(context);
  36. },
  37. child: Text('Close')),
  38. FlatButton(
  39. onPressed: () {
  40. print('Informed');
  41. _dismissDialog(context);
  42. },
  43. child: Text('Informed!'),
  44. )
  45. ],
  46. );
  47. });
  48. }
  49.  
  50. static _dismissDialog(BuildContext context) {
  51. Navigator.pop(context);
  52. }
  53.  
  54. static Future<bool> signInWithEmail(String email, String password) async {
  55. try {
  56. AuthResult result = await _auth.signInWithEmailAndPassword(
  57. email: email, password: password);
  58. FirebaseUser user = result.user;
  59. if (user != null)
  60. return true;
  61. else {
  62. print(user.email.toString());
  63. return false;
  64. }
  65. } catch (e) {
  66. return false;
  67. }
  68. }
  69.  
  70. static void uploadForm(BuildContext context) {
  71. showDialog(
  72. context: context,
  73. builder: (context) {
  74. return CupertinoAlertDialog(
  75. title: Text('Upload Image\n'),
  76.  
  77. actions: <Widget>[
  78. Scaffold(
  79. body: Container(
  80. child: Column(
  81. mainAxisAlignment: MainAxisAlignment.center,
  82. children: <Widget>[
  83. Container(
  84. child: new CircleAvatar(
  85. child: const Text('C'),
  86. foregroundColor: Colors.white,
  87. ),
  88. width: 120.0,
  89. height: 120.0,
  90. padding: const EdgeInsets.all(2.0),
  91. // borde width
  92. decoration: new BoxDecoration(
  93. color: const Color(0xFFFFFFFF), // border color
  94. shape: BoxShape.circle,
  95. )),
  96. Container(
  97. child: TextFormField(
  98. controller: _imageName,
  99. // keyboardType: TextInputType.,
  100. obscureText: true,
  101. decoration: InputDecoration(
  102. labelText: "Password ",
  103. icon: Icon(Icons.vpn_key),
  104. hintText: "Eg : **********"),
  105.  
  106. validator: (value) {
  107. if (value.isEmpty) {
  108. return "password Can't be Empty";
  109. } else if (value.length < 6) {
  110. return "Your Password is weak";
  111. }
  112. return null;
  113. },
  114. ),
  115. ),
  116. FlatButton(
  117. onPressed: () {
  118. _dismissDialog(context);
  119. },
  120. child: Text('Close')),
  121. FlatButton(
  122. onPressed: () {
  123. print('upload');
  124. _dismissDialog(context);
  125. },
  126. child: Text('Upload!'),
  127. )
  128. ],
  129. ),
  130. ),
  131. ),
  132.  
  133.  
  134. ],
  135. );
  136. });
  137. }
  138.  
  139. //
  140. // Future getImage() async {
  141. //// var image = await ImagePicker.pickImage(source: ImageSource.gallery);
  142. ////
  143. //// setState(() {
  144. //// _image = image;
  145. //// print('Image Path $_image');
  146. //// });
  147. // }
  148. //
  149. // Future uploadPic(BuildContext context) async {
  150. // String fileName = basename(_image.path);
  151. // StorageReference firebaseStorageRef = FirebaseStorage.instance.ref().child(fileName);
  152. // StorageUploadTask uploadTask = firebaseStorageRef.putFile(_image);
  153. // StorageTaskSnapshot taskSnapshot=await uploadTask.onComplete;
  154. // setState(() {
  155. // print("Profile Picture uploaded");
  156. // Scaffold.of(context).showSnackBar(SnackBar(content: Text('Profile Picture Uploaded')));
  157. // });
  158. // }
  159.  
  160.  
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement