Skip to content

Commit

Permalink
refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
mikezamayias committed Jan 23, 2022
1 parent 21955f7 commit ddf295f
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 68 deletions.
1 change: 0 additions & 1 deletion lib/models/phone/phone_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ abstract class PhoneModel implements _$PhoneModel {
const PhoneModel._();

const factory PhoneModel({
required String uid,
required String model,
required String imageUrl,
required String soc,
Expand Down
35 changes: 6 additions & 29 deletions lib/models/phone/phone_model.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class _$PhoneModelTearOff {
const _$PhoneModelTearOff();

_PhoneModel call(
{required String uid,
required String model,
{required String model,
required String imageUrl,
required String soc,
required int ram,
Expand All @@ -36,7 +35,6 @@ class _$PhoneModelTearOff {
required int stock,
required double sar}) {
return _PhoneModel(
uid: uid,
model: model,
imageUrl: imageUrl,
soc: soc,
Expand All @@ -61,7 +59,6 @@ const $PhoneModel = _$PhoneModelTearOff();

/// @nodoc
mixin _$PhoneModel {
String get uid => throw _privateConstructorUsedError;
String get model => throw _privateConstructorUsedError;
String get imageUrl => throw _privateConstructorUsedError;
String get soc => throw _privateConstructorUsedError;
Expand All @@ -86,8 +83,7 @@ abstract class $PhoneModelCopyWith<$Res> {
PhoneModel value, $Res Function(PhoneModel) then) =
_$PhoneModelCopyWithImpl<$Res>;
$Res call(
{String uid,
String model,
{String model,
String imageUrl,
String soc,
int ram,
Expand All @@ -110,7 +106,6 @@ class _$PhoneModelCopyWithImpl<$Res> implements $PhoneModelCopyWith<$Res> {

@override
$Res call({
Object? uid = freezed,
Object? model = freezed,
Object? imageUrl = freezed,
Object? soc = freezed,
Expand All @@ -124,10 +119,6 @@ class _$PhoneModelCopyWithImpl<$Res> implements $PhoneModelCopyWith<$Res> {
Object? sar = freezed,
}) {
return _then(_value.copyWith(
uid: uid == freezed
? _value.uid
: uid // ignore: cast_nullable_to_non_nullable
as String,
model: model == freezed
? _value.model
: model // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -183,8 +174,7 @@ abstract class _$PhoneModelCopyWith<$Res> implements $PhoneModelCopyWith<$Res> {
__$PhoneModelCopyWithImpl<$Res>;
@override
$Res call(
{String uid,
String model,
{String model,
String imageUrl,
String soc,
int ram,
Expand All @@ -209,7 +199,6 @@ class __$PhoneModelCopyWithImpl<$Res> extends _$PhoneModelCopyWithImpl<$Res>

@override
$Res call({
Object? uid = freezed,
Object? model = freezed,
Object? imageUrl = freezed,
Object? soc = freezed,
Expand All @@ -223,10 +212,6 @@ class __$PhoneModelCopyWithImpl<$Res> extends _$PhoneModelCopyWithImpl<$Res>
Object? sar = freezed,
}) {
return _then(_PhoneModel(
uid: uid == freezed
? _value.uid
: uid // ignore: cast_nullable_to_non_nullable
as String,
model: model == freezed
? _value.model
: model // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -279,8 +264,7 @@ class __$PhoneModelCopyWithImpl<$Res> extends _$PhoneModelCopyWithImpl<$Res>
@JsonSerializable()
class _$_PhoneModel extends _PhoneModel {
const _$_PhoneModel(
{required this.uid,
required this.model,
{required this.model,
required this.imageUrl,
required this.soc,
required this.ram,
Expand All @@ -296,8 +280,6 @@ class _$_PhoneModel extends _PhoneModel {
factory _$_PhoneModel.fromJson(Map<String, dynamic> json) =>
_$$_PhoneModelFromJson(json);

@override
final String uid;
@override
final String model;
@override
Expand All @@ -323,15 +305,14 @@ class _$_PhoneModel extends _PhoneModel {

@override
String toString() {
return 'PhoneModel(uid: $uid, model: $model, imageUrl: $imageUrl, soc: $soc, ram: $ram, storage: $storage, screenSize: $screenSize, battery: $battery, camera: $camera, price: $price, stock: $stock, sar: $sar)';
return 'PhoneModel(model: $model, imageUrl: $imageUrl, soc: $soc, ram: $ram, storage: $storage, screenSize: $screenSize, battery: $battery, camera: $camera, price: $price, stock: $stock, sar: $sar)';
}

@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _PhoneModel &&
const DeepCollectionEquality().equals(other.uid, uid) &&
const DeepCollectionEquality().equals(other.model, model) &&
const DeepCollectionEquality().equals(other.imageUrl, imageUrl) &&
const DeepCollectionEquality().equals(other.soc, soc) &&
Expand All @@ -349,7 +330,6 @@ class _$_PhoneModel extends _PhoneModel {
@override
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(uid),
const DeepCollectionEquality().hash(model),
const DeepCollectionEquality().hash(imageUrl),
const DeepCollectionEquality().hash(soc),
Expand All @@ -375,8 +355,7 @@ class _$_PhoneModel extends _PhoneModel {

abstract class _PhoneModel extends PhoneModel {
const factory _PhoneModel(
{required String uid,
required String model,
{required String model,
required String imageUrl,
required String soc,
required int ram,
Expand All @@ -392,8 +371,6 @@ abstract class _PhoneModel extends PhoneModel {
factory _PhoneModel.fromJson(Map<String, dynamic> json) =
_$_PhoneModel.fromJson;

@override
String get uid;
@override
String get model;
@override
Expand Down
2 changes: 0 additions & 2 deletions lib/models/phone/phone_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lib/models/user/user_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ abstract class UserModel implements _$UserModel {
const UserModel._();

const factory UserModel({
required String uid,
required String firstName,
required String lastName,
required String email,
Expand Down
35 changes: 6 additions & 29 deletions lib/models/user/user_model.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ class _$UserModelTearOff {
const _$UserModelTearOff();

_UserModel call(
{required String uid,
required String firstName,
{required String firstName,
required String lastName,
required String email,
required String phoneNumber,
required String streetAddress,
required int postalCode,
required String city}) {
return _UserModel(
uid: uid,
firstName: firstName,
lastName: lastName,
email: email,
Expand All @@ -53,7 +51,6 @@ const $UserModel = _$UserModelTearOff();

/// @nodoc
mixin _$UserModel {
String get uid => throw _privateConstructorUsedError;
String get firstName => throw _privateConstructorUsedError;
String get lastName => throw _privateConstructorUsedError;
String get email => throw _privateConstructorUsedError;
Expand All @@ -73,8 +70,7 @@ abstract class $UserModelCopyWith<$Res> {
factory $UserModelCopyWith(UserModel value, $Res Function(UserModel) then) =
_$UserModelCopyWithImpl<$Res>;
$Res call(
{String uid,
String firstName,
{String firstName,
String lastName,
String email,
String phoneNumber,
Expand All @@ -93,7 +89,6 @@ class _$UserModelCopyWithImpl<$Res> implements $UserModelCopyWith<$Res> {

@override
$Res call({
Object? uid = freezed,
Object? firstName = freezed,
Object? lastName = freezed,
Object? email = freezed,
Expand All @@ -103,10 +98,6 @@ class _$UserModelCopyWithImpl<$Res> implements $UserModelCopyWith<$Res> {
Object? city = freezed,
}) {
return _then(_value.copyWith(
uid: uid == freezed
? _value.uid
: uid // ignore: cast_nullable_to_non_nullable
as String,
firstName: firstName == freezed
? _value.firstName
: firstName // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -146,8 +137,7 @@ abstract class _$UserModelCopyWith<$Res> implements $UserModelCopyWith<$Res> {
__$UserModelCopyWithImpl<$Res>;
@override
$Res call(
{String uid,
String firstName,
{String firstName,
String lastName,
String email,
String phoneNumber,
Expand All @@ -167,7 +157,6 @@ class __$UserModelCopyWithImpl<$Res> extends _$UserModelCopyWithImpl<$Res>

@override
$Res call({
Object? uid = freezed,
Object? firstName = freezed,
Object? lastName = freezed,
Object? email = freezed,
Expand All @@ -177,10 +166,6 @@ class __$UserModelCopyWithImpl<$Res> extends _$UserModelCopyWithImpl<$Res>
Object? city = freezed,
}) {
return _then(_UserModel(
uid: uid == freezed
? _value.uid
: uid // ignore: cast_nullable_to_non_nullable
as String,
firstName: firstName == freezed
? _value.firstName
: firstName // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -217,8 +202,7 @@ class __$UserModelCopyWithImpl<$Res> extends _$UserModelCopyWithImpl<$Res>
@JsonSerializable()
class _$_UserModel extends _UserModel {
const _$_UserModel(
{required this.uid,
required this.firstName,
{required this.firstName,
required this.lastName,
required this.email,
required this.phoneNumber,
Expand All @@ -230,8 +214,6 @@ class _$_UserModel extends _UserModel {
factory _$_UserModel.fromJson(Map<String, dynamic> json) =>
_$$_UserModelFromJson(json);

@override
final String uid;
@override
final String firstName;
@override
Expand All @@ -249,15 +231,14 @@ class _$_UserModel extends _UserModel {

@override
String toString() {
return 'UserModel(uid: $uid, firstName: $firstName, lastName: $lastName, email: $email, phoneNumber: $phoneNumber, streetAddress: $streetAddress, postalCode: $postalCode, city: $city)';
return 'UserModel(firstName: $firstName, lastName: $lastName, email: $email, phoneNumber: $phoneNumber, streetAddress: $streetAddress, postalCode: $postalCode, city: $city)';
}

@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _UserModel &&
const DeepCollectionEquality().equals(other.uid, uid) &&
const DeepCollectionEquality().equals(other.firstName, firstName) &&
const DeepCollectionEquality().equals(other.lastName, lastName) &&
const DeepCollectionEquality().equals(other.email, email) &&
Expand All @@ -273,7 +254,6 @@ class _$_UserModel extends _UserModel {
@override
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(uid),
const DeepCollectionEquality().hash(firstName),
const DeepCollectionEquality().hash(lastName),
const DeepCollectionEquality().hash(email),
Expand All @@ -295,8 +275,7 @@ class _$_UserModel extends _UserModel {

abstract class _UserModel extends UserModel {
const factory _UserModel(
{required String uid,
required String firstName,
{required String firstName,
required String lastName,
required String email,
required String phoneNumber,
Expand All @@ -308,8 +287,6 @@ abstract class _UserModel extends UserModel {
factory _UserModel.fromJson(Map<String, dynamic> json) =
_$_UserModel.fromJson;

@override
String get uid;
@override
String get firstName;
@override
Expand Down
2 changes: 0 additions & 2 deletions lib/models/user/user_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lib/services/authentication_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class AuthenticationService {
password: password,
);
UserModel userModel = UserModel(
uid: authResult.user!.uid,
email: email,
firstName: firstName,
lastName: lastName,
Expand Down
8 changes: 5 additions & 3 deletions lib/services/firestore_service.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:cloud_firestore/cloud_firestore.dart';

import '../locator.dart';
import '../models/phone/phone_model.dart';
import '../models/user/user_model.dart';
import 'authentication_service.dart';

class FirestoreService {
/// Firestore instance
Expand Down Expand Up @@ -45,7 +47,9 @@ class FirestoreService {

// Create User
Future<void> createUser(UserModel userModel) async {
return userCollection.doc(userModel.uid).set(userModel.toDocument());
return userCollection
.doc(locator<AuthenticationService>().currentUser!.uid)
.set(userModel.toDocument());
}

// Read User
Expand All @@ -60,8 +64,6 @@ class FirestoreService {

// Stream User Model
Stream<UserModel?> streamUser(String? documentId) {
print('streamUser: $documentId');
print('streamUser: ${userCollection.doc(documentId)}');
return userCollection
.doc(documentId)
.snapshots()
Expand Down

0 comments on commit ddf295f

Please sign in to comment.