Skip to content

Commit

Permalink
feat: integrate survey detail (#28)
Browse files Browse the repository at this point in the history
# Conflicts:
#	lib/modules/survey_detail/components/content.dart
  • Loading branch information
markgravity committed Jun 30, 2021
1 parent 4416d4c commit 9031913
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 65 deletions.
1 change: 1 addition & 0 deletions lib/modules/home/components/body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Body extends StatelessWidget {
isShown: isLoading,
baseColor: Colors.white.withOpacity(0.12),
highlightColor: Colors.white.withOpacity(0.5),
transition: BoneTransition.none,
child: child!,
),
child: Stack(
Expand Down
5 changes: 4 additions & 1 deletion lib/modules/home/home_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class HomeRouterImpl extends HomeRouter {
@override
void pushToSurveyDetail(
{required BuildContext context, required SurveyInfo survey}) {
context.navigator.pushNamed(SurveyDetailModule.routePath);
context.navigator.pushNamed(
SurveyDetailModule.routePath,
arguments: SurveyDetailArguments(survey: survey),
);
}
}
118 changes: 69 additions & 49 deletions lib/modules/survey_detail/components/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,82 @@ class Content extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Screen(
body: Stack(
fit: StackFit.expand,
children: [
Image(
image: Assets.images.mainBackgroundDimmed,
fit: BoxFit.fill,
),
SafeArea(
child: Column(
children: [
NavigationBar(),
Expanded(
child: Container(
margin: const EdgeInsets.fromLTRB(20, 0, 20, 0),
child: Column(
children: [
const Text(
"Working from home Check-In",
style: TextStyle(
color: Colors.white,
fontSize: 34,
final state = context.findAncestorStateOfType<_SurveyDetailViewImplState>()!;

return StreamsSelector0<bool>.value(
stream: state.isProgressHUDShown,
builder: (_, isShown, child) => ProgressHUD(
isShow: isShown,
child: child!,
),
child: Screen(
body: Stack(
fit: StackFit.expand,
children: [
StreamsSelector0<SurveyInfo>.value(
stream: state._survey,
builder: (_, survey, __) => Image(
image: NetworkImage(survey.coverImageUrl!),
fit: BoxFit.fill,
),
),
SafeArea(
child: Column(
children: [
NavigationBar(),
Expanded(
child: Container(
margin: const EdgeInsets.fromLTRB(20, 0, 20, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
StreamsSelector0<SurveyInfo>.value(
stream: state._survey,
builder: (_, survey, __) => Text(
survey.title!,
style: const TextStyle(
color: Colors.white,
fontSize: 34,
),
),
),
const SizedBox(
height: 17,
),
),
const SizedBox(
height: 17,
),
Text(
"We would like to know how you feel about our work from home (WFH) experience.",
style: TextStyle(
color: Colors.white.withOpacity(0.7),
fontSize: 17,
StreamsSelector0<SurveyInfo>.value(
stream: state._survey,
builder: (_, survey, __) => Text(
survey.description!,
style: TextStyle(
color: Colors.white.withOpacity(0.7),
fontSize: 17,
),
),
),
),
],
],
),
),
),
),
],
],
),
),
),
Positioned(
right: 20,
bottom: 0,
child: SafeArea(
child: ConstrainedBox(
constraints: const BoxConstraints(
minWidth: 140,
),
child: Button(
title: AppLocalizations.of(context)!.surveyDetailScreenStartSurveyButtonTitle,
Positioned(
right: 20,
bottom: 0,
child: SafeArea(
child: ConstrainedBox(
constraints: const BoxConstraints(
minWidth: 140,
),
child: Button(
onPressed: () => state.delegate?.startSurveyButtonDidTap.add(null),
title: AppLocalizations.of(context)!.surveyDetailScreenStartSurveyButtonTitle,
),
),
),
),
)
],
)
],
),
),
);
}
Expand Down
30 changes: 26 additions & 4 deletions lib/modules/survey_detail/survey_detail_interactor.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
part of 'survey_detail_module.dart';

abstract class SurveyDetailInteractorDelegate {}
abstract class SurveyDetailInteractorDelegate {
BehaviorSubject<DetailedSurveyInfo> get detailedSurveyDidFetch;

abstract class SurveyDetailInteractor
extends Interactor<SurveyDetailInteractorDelegate> {}
BehaviorSubject<Exception> get detailedSurveyDidFailToFetch;
}

class SurveyDetailInteractorImpl extends SurveyDetailInteractor {}
abstract class SurveyDetailInteractor extends ArgumentsInteractor<
SurveyDetailInteractorDelegate, SurveyDetailArguments> {
SurveyInfo get survey;

void fetchDetailedSurvey();
}

class SurveyDetailInteractorImpl extends SurveyDetailInteractor {
final SurveyRepository _surveyRepository = locator.get();

@override
SurveyInfo get survey => arguments!.survey;

@override
void fetchDetailedSurvey() {
_surveyRepository
.fetchDetailedSurvey(survey.id!)
.then((value) => delegate?.detailedSurveyDidFetch.add(value))
.onError<Exception>((exception, _) =>
delegate?.detailedSurveyDidFailToFetch.add(exception));
}
}
22 changes: 19 additions & 3 deletions lib/modules/survey_detail/survey_detail_module.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import 'package:flutter/material.dart' hide Router;
import 'package:flutter/widgets.dart' hide Router;
import 'package:streams_provider/streams_provider.dart';
import 'package:survey/components/alert/alert.dart';
import 'package:survey/components/button/button.dart';
import 'package:survey/components/common/progress_hud.dart';
import 'package:survey/components/navigation_bar/navigation_bar.dart';
import 'package:survey/core/viper/module.dart';
import 'package:survey/gen/assets.gen.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:survey/models/detailed_survey_info.dart';
import 'package:survey/models/survey_info.dart';
import 'package:survey/modules/screen.dart';
import 'package:survey/repositories/survey_repository.dart';
import 'package:survey/services/locator/locator_service.dart';

part 'survey_detail_view.dart';

Expand All @@ -17,12 +23,22 @@ part 'survey_detail_router.dart';

part 'components/content.dart';

class SurveyDetailModule extends Module<SurveyDetailView,
SurveyDetailInteractor, SurveyDetailPresenter, SurveyDetailRouter> {
class SurveyDetailModule extends ArgumentsModule<
SurveyDetailView,
SurveyDetailInteractor,
SurveyDetailPresenter,
SurveyDetailRouter,
SurveyDetailArguments> {
static const routePath = "/survey/detail";

@override
Widget build(BuildContext context) {
return const SurveyDetailViewImpl();
}
}

class SurveyDetailArguments extends ModuleArguments {
SurveyDetailArguments({required this.survey});

final SurveyInfo survey;
}
48 changes: 47 additions & 1 deletion lib/modules/survey_detail/survey_detail_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,50 @@ abstract class SurveyDetailPresenter extends Presenter<SurveyDetailView,
SurveyDetailInteractor, SurveyDetailRouter> {}

class SurveyDetailPresenterImpl extends SurveyDetailPresenter
implements SurveyDetailViewDelegate, SurveyDetailInteractorDelegate {}
implements SurveyDetailViewDelegate, SurveyDetailInteractorDelegate {
SurveyDetailPresenterImpl() {
stateDidInit.voidListen(_stateDidInit).addTo(disposeBag);
startSurveyButtonDidTap
.voidListen(_startSurveyButtonDidTap)
.addTo(disposeBag);

detailedSurveyDidFetch.listen(_detailedSurveyDidFetch).addTo(disposeBag);
detailedSurveyDidFailToFetch
.listen(_detailedSurveyDidFailToFetch)
.addTo(disposeBag);
}

@override
final detailedSurveyDidFailToFetch = BehaviorSubject<Exception>();

@override
final detailedSurveyDidFetch = BehaviorSubject<DetailedSurveyInfo>();

@override
final alertDialogDidClose = BehaviorSubject<void>();

@override
final stateDidInit = BehaviorSubject<void>();

@override
final startSurveyButtonDidTap = BehaviorSubject<void>();

void _stateDidInit() {
view.setSurvey(interactor.survey);
}

void _startSurveyButtonDidTap() {
view.showProgressHUD();
interactor.fetchDetailedSurvey();
}

void _detailedSurveyDidFetch(DetailedSurveyInfo survey) {
view.dismissProgressHUD();
router.pushToSurveyQuestionsScreen(view.context, survey: survey);
}

void _detailedSurveyDidFailToFetch(Exception exception) {
view.dismissProgressHUD();
view.alert(exception);
}
}
11 changes: 9 additions & 2 deletions lib/modules/survey_detail/survey_detail_router.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
part of 'survey_detail_module.dart';

abstract class SurveyDetailRouter extends Router {}
abstract class SurveyDetailRouter extends Router {
void pushToSurveyQuestionsScreen(BuildContext context,
{required DetailedSurveyInfo survey});
}

class SurveyDetailRouterImpl extends SurveyDetailRouter {}
class SurveyDetailRouterImpl extends SurveyDetailRouter {
@override
void pushToSurveyQuestionsScreen(BuildContext context,
{required DetailedSurveyInfo survey}) {}
}
33 changes: 30 additions & 3 deletions lib/modules/survey_detail/survey_detail_view.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
part of 'survey_detail_module.dart';

abstract class SurveyDetailViewDelegate {}
abstract class SurveyDetailViewDelegate implements AlertViewMixinDelegate {
BehaviorSubject<void> get stateDidInit;

abstract class SurveyDetailView extends View<SurveyDetailViewDelegate> {}
BehaviorSubject<void> get startSurveyButtonDidTap;
}

abstract class SurveyDetailView extends View<SurveyDetailViewDelegate>
with ProgressHUDViewMixin, AlertViewMixin {
void setSurvey(SurveyInfo survey);
}

class SurveyDetailViewImpl extends StatefulWidget {
const SurveyDetailViewImpl({Key? key}) : super(key: key);
Expand All @@ -12,9 +19,29 @@ class SurveyDetailViewImpl extends StatefulWidget {
}

class _SurveyDetailViewImplState extends ViewState<SurveyDetailViewImpl,
SurveyDetailModule, SurveyDetailViewDelegate> implements SurveyDetailView {
SurveyDetailModule, SurveyDetailViewDelegate>
with ProgressHUDViewMixin, AlertViewMixin
implements SurveyDetailView {
late final _survey = BehaviorSubject<SurveyInfo>();

@override
void initState() {
super.initState();
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
delegate?.stateDidInit.add(null);
}

@override
Widget build(BuildContext context) {
return const Content();
}

@override
void setSurvey(SurveyInfo survey) {
_survey.add(survey);
}
}
6 changes: 4 additions & 2 deletions test/modules/home/home_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ void main() {
beforeEach(() {
when(buildContext.findAncestorStateOfType<NavigatorState>())
.thenReturn(navigatorState);
when(navigatorState.pushNamed(any)).thenAnswer((_) => Future.value());
when(navigatorState.pushNamed(any, arguments: anyNamed("arguments")))
.thenAnswer((_) => Future.value());
router.pushToSurveyDetail(context: buildContext, survey: SurveyInfo());
});

it("triggers navigator to push to Survey Detail screen", () {
final routePath = verify(navigatorState.pushNamed(captureAny))
final routePath = verify(navigatorState.pushNamed(captureAny,
arguments: anyNamed("arguments")))
.captured
.single as String;
expect(routePath, SurveyDetailModule.routePath);
Expand Down

0 comments on commit 9031913

Please sign in to comment.