Skip to content

Commit

Permalink
[#17] Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nkhanh44 committed Aug 30, 2023
1 parent 9b5181d commit 0ae502c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
8 changes: 0 additions & 8 deletions lib/screens/home/home_pages_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const _imageOpacity = 0.6;
class HomePagesWidget extends StatefulWidget {
final List<SurveyModel> surveys;
final ValueNotifier<int> currentPage;
final PageController _pageController = PageController();
final VoidCallback onNextButtonPressed;
final bool isRefreshing;
final VoidCallback onLoadMore;
Expand All @@ -37,13 +36,6 @@ class _HomePagesWidgetState extends State<HomePagesWidget> {
super.dispose();
}

void _handleNextButtonPressed(int index) {
if (widget.currentPage.value < widget.surveys.length - 1) {
widget.currentPage.value = index + 1;
_pageController.jumpToPage(widget.currentPage.value);
}
}

void _handlePageChanged(int index) {
widget.currentPage.value = index;

Expand Down
4 changes: 2 additions & 2 deletions lib/screens/home/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class _HomeScreenState extends ConsumerState<HomeScreen> {
extra: survey,
);
},
onLoadMore: _loadSurveys,
isRefreshing: isRefreshing
onLoadMore: _loadSurveys,
isRefreshing: isRefreshing,
),
const HomeHeaderWidget(),
Align(
Expand Down
9 changes: 3 additions & 6 deletions lib/screens/home/home_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:survey_flutter/usecases/get_cached_surveys_use_case.dart';
import 'package:survey_flutter/usecases/get_surveys_use_case.dart';

int _pageNumber = 1;
const _pageSize = 5;
const _pageSize = 10;
List<SurveyModel> _loadedSurveys = [];

final homeViewModelProvider =
Expand Down Expand Up @@ -40,14 +40,11 @@ class HomeViewModel extends StateNotifier<HomeState> {
Stream<String> get error => _error.stream;

void _handleError(Failed result) {
var errorMessage = result.getErrorMessage();
var isNotFoundError = result.isNotFoundError();

if (isNotFoundError) {
if (result.isNotFoundError()) {
_surveys.add(_loadedSurveys);
state = const HomeState.loadSurveysSuccess(false);

Check warning on line 45 in lib/screens/home/home_view_model.dart

View check run for this annotation

Codecov / codecov/patch

lib/screens/home/home_view_model.dart#L44-L45

Added lines #L44 - L45 were not covered by tests
} else {
_error.add(errorMessage);
_error.add(result.getErrorMessage());
state = const HomeState.error();
}
}
Expand Down

0 comments on commit 0ae502c

Please sign in to comment.