Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
salahamassi committed Mar 31, 2024
1 parent ebf5974 commit b994293
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:bond_network/bond_network.dart';
import 'package:bond_notifications/bond_notifications.dart';
import 'package:dio/dio.dart';

class NotificationCenterRemoteDataSource extends NotificationCenterDataSource {
final ApiClient _client;
Expand All @@ -10,11 +9,12 @@ class NotificationCenterRemoteDataSource extends NotificationCenterDataSource {
@override
Future<ListResponse<ServerNotificationModel>> loadNotifications(
{String? nextUrl}) async {
final Response<dynamic> response = await _client.get(
nextUrl ?? NotificationsApis.notifications,
headers: Api.headers(),
);
return mapListResponse(response);
// final Response<dynamic> response = await _client.get(
// nextUrl ?? NotificationsApis.notifications,
// headers: Api.headers(),
// );
// return mapListResponse(response);
return ListResponse<ServerNotificationModel>.fromJson(const {"data": []});
}

@override
Expand Down
1 change: 1 addition & 0 deletions lib/core/theme/app_light_theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ ThemeData appLightThemeData() {
textStyle: appTextTheme.titleSmall?.copyWith(
color: Colors.black,
),
color: Colors.white,
),

/// Text theme
Expand Down
3 changes: 2 additions & 1 deletion lib/core/widgets/bond_pop_menu/bond_pop_menu_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ class BondPopMenuButton extends ConsumerWidget {
ref.read(localProvider.notifier).update(newLocale);
break;
case Menu.logout:
ref.context.go('/login');
break;
case Menu.notifications:
ref.context.go('/notifications');
ref.context.push('/notifications');
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class NewAccountView extends StatelessWidget {
),
TextSpan(
recognizer: TapGestureRecognizer()
..onTap = () => context.go('/register'),
..onTap = () => context.push('/register'),
text: context.localizations.login_page_new_account_button,
style: context.textTheme.labelSmall,
),
Expand Down
11 changes: 11 additions & 0 deletions lib/features/post/data/api.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:bond/features/post/data/post_faker.dart';
import 'package:bond_network/bond_network.dart';

import 'models/post.dart';
Expand All @@ -7,6 +8,16 @@ class PostsApi {

PostsApi(this._bondFire);

Future<ListResponse<Post>> fakePosts() => Future.delayed(
const Duration(seconds: 1),
() => ListResponse<Post>.fromJson(PostFaker.posts()),
);

Future<SingleResponse<Post>> fakePost() => Future.delayed(
const Duration(seconds: 1),
() => SingleResponse<Post>.fromJson({'data': PostFaker.post()}),
);

Future<ListResponse<Post>> posts() => _bondFire
.get<ListResponse<Post>>('/posts')
.cache()
Expand Down
63 changes: 63 additions & 0 deletions lib/features/post/data/post_faker.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'dart:math';

import 'package:faker/faker.dart' show Faker, Internet;

class PostFaker {
static Map<String, dynamic> posts() {
return {
'data': List.generate(10, (index) => post()),
};
}

static Map<String, dynamic> post() {
final faker = Faker();

// Constructing thumbnail URL with random parameters
const imageUrl = 'https://fakeimg.pl/600x400';

return {
'uuid': faker.guid.guid(),
'created_at': faker.date.dateTime().toIso8601String(),
'updated_at': faker.date.dateTime().toIso8601String(),
'color': faker.internet.color(),
'description': faker.lorem.sentence(),
'urls': {
'thumb': imageUrl,
'full': imageUrl,
'raw': imageUrl,
'small': imageUrl,
'regular': imageUrl,
'small_s3': imageUrl,
},
'likes': faker.randomGenerator.integer(1000),
'author': {
'uuid': faker.guid.guid(),
'name': faker.person.name(),
'username': faker.person.name(),
'first_name': faker.person.firstName(),
'last_name': faker.person.lastName(),
'avatar': faker.internet.httpsUrl(),
'updated_at': faker.date.dateTime().toIso8601String(),
'twitter_username': faker.person.name(),
'bio': faker.lorem.sentence(),
'total_likes': faker.randomGenerator.integer(1000),
'total_photos': faker.randomGenerator.integer(1000),
'instagram_username': faker.person.name(),
},
'views': faker.randomGenerator.integer(1000),
'downloads': faker.randomGenerator.integer(1000),
};
}
}

extension XInternet on Internet {
String color() {
final random = Random();
const hexDigits = '0123456789ABCDEF';
String color = '';
for (int i = 0; i < 6; i++) {
color += hexDigits[random.nextInt(16)];
}
return color;
}
}
4 changes: 1 addition & 3 deletions lib/features/post/presentations/posts_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ class PostsPage extends ConsumerWidget {
],
),
),
error: (error, _) => Center(
child: Text(error.toString()),
),
error: (error, stackTrace) => Center(child: Text(error.toString())),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
final postFeatureProvider =
FutureProvider.autoDispose.family<Post, String>((ref, id) async {
final api = sl<PostsApi>();
final response = await api.post(id);
final response = await api.fakePost();
return response.data;
});
29 changes: 16 additions & 13 deletions lib/features/post/presentations/providers/posts_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,32 @@ final postsProvider =
);

class PostController extends AutoDisposeAsyncNotifier<ListState<Post>> {
PostController(this._api, this.scrollController) : super() {
scrollController.addListener(_scrollControllerListener);
ref.onDispose(
() {
scrollController.dispose();
scrollController.removeListener(_scrollControllerListener);
},
);
}
PostController(this._api, this.scrollController) : super();

final PostsApi _api;
final ScrollController scrollController;

@override
Future<ListState<Post>> build() async {
final response = await _api.posts();
_initialize();
final response = await _api.fakePosts();
return ListState.data(response);
}

void loadMore() async {
void _initialize() {
scrollController.addListener(_scrollControllerListener);
ref.onDispose(
() {
scrollController.dispose();
scrollController.removeListener(_scrollControllerListener);
},
);
}

void _loadMore() async {
state = AsyncData(state.requireValue.loading());
state = await AsyncValue.guard(() async {
final response = await _api.posts();
final response = await _api.fakePosts();
return state.requireValue.success(response);
});
}
Expand All @@ -49,7 +52,7 @@ class PostController extends AutoDisposeAsyncNotifier<ListState<Post>> {
const delta = 200.0;
if (maxScroll - currentScroll <= delta &&
state.value?.status != ListStatus.loading) {
loadMore();
_loadMore();
}
}
}
2 changes: 1 addition & 1 deletion lib/features/post/presentations/views/post_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PostItem extends StatelessWidget {
Widget build(BuildContext context) {
return GridTile(
child: GestureDetector(
onTap: () => context.go('/post/${post.uuid}'),
onTap: () => context.push('/post/${post.uuid}'),
child: Hero(
tag: post.uuid,
child: ClipRRect(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ packages:
source: hosted
version: "1.3.1"
faker:
dependency: transitive
dependency: "direct main"
description:
name: faker
sha256: "746e59f91d8b06a389e74cf76e909a05ed69c12691768e2f93557fdf29200fd0"
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ dependencies:
timeago: ^3.3.0
args: ^2.3.1
device_info_plus: ^10.0.1
faker: ^2.1.0

# platforms packages
universal_platform: ^1.0.0+1
Expand Down

0 comments on commit b994293

Please sign in to comment.