|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:survey_flutter/gen/assets.gen.dart'; |
| 3 | +import 'package:survey_flutter/model/survey_model.dart'; |
| 4 | +import 'package:survey_flutter/theme/app_constants.dart'; |
| 5 | +import 'package:survey_flutter/theme/primary_button_style.dart'; |
| 6 | +import 'package:survey_flutter/utils/build_context_ext.dart'; |
| 7 | + |
| 8 | +const _buttonHeight = 56.0; |
| 9 | + |
| 10 | +class SurveyScreen extends StatelessWidget { |
| 11 | + final SurveyModel survey; |
| 12 | + SurveyScreen({ |
| 13 | + super.key, |
| 14 | + required this.survey, |
| 15 | + }); |
| 16 | + |
| 17 | + late final _backgroundImage = FadeInImage.assetNetwork( |
| 18 | + placeholder: Assets.images.placeholder.path, |
| 19 | + image: survey.coverImageUrl, |
| 20 | + fit: BoxFit.cover, |
| 21 | + width: double.infinity, |
| 22 | + height: double.infinity, |
| 23 | + ); |
| 24 | + |
| 25 | + late final _gradientOverlay = Container( |
| 26 | + decoration: BoxDecoration( |
| 27 | + gradient: LinearGradient( |
| 28 | + begin: Alignment.topCenter, |
| 29 | + end: Alignment.bottomCenter, |
| 30 | + colors: [ |
| 31 | + Colors.black.withOpacity(0.8), |
| 32 | + Colors.black.withOpacity(0.2), |
| 33 | + Colors.black.withOpacity(0.8), |
| 34 | + ], |
| 35 | + ), |
| 36 | + ), |
| 37 | + ); |
| 38 | + |
| 39 | + Widget _buildTitle(BuildContext context) { |
| 40 | + return Text( |
| 41 | + survey.title, |
| 42 | + style: context.textTheme.titleMedium, |
| 43 | + maxLines: 2, |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + Widget _buildDescription(BuildContext context) { |
| 48 | + return Text( |
| 49 | + survey.description, |
| 50 | + style: context.textTheme.bodyMedium, |
| 51 | + maxLines: 2, |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + Widget _buildButton(BuildContext context) { |
| 56 | + return SizedBox( |
| 57 | + height: _buttonHeight, |
| 58 | + child: ElevatedButton( |
| 59 | + style: PrimaryButtonStyle( |
| 60 | + hintTextStyle: context.textTheme.labelMedium, |
| 61 | + ), |
| 62 | + child: Text( |
| 63 | + context.localizations.startSurveyButton, |
| 64 | + ), |
| 65 | + onPressed: () { |
| 66 | + // TODO: Start survey |
| 67 | + }, |
| 68 | + ), |
| 69 | + ); |
| 70 | + } |
| 71 | + |
| 72 | + @override |
| 73 | + Widget build(BuildContext context) { |
| 74 | + return Scaffold( |
| 75 | + appBar: AppBar( |
| 76 | + backgroundColor: Colors.transparent, |
| 77 | + elevation: 0, |
| 78 | + ), |
| 79 | + extendBodyBehindAppBar: true, |
| 80 | + body: Stack( |
| 81 | + children: [ |
| 82 | + _backgroundImage, |
| 83 | + _gradientOverlay, |
| 84 | + Container( |
| 85 | + padding: const EdgeInsets.only( |
| 86 | + bottom: Metrics.spacing20, |
| 87 | + left: Metrics.spacing20, |
| 88 | + right: Metrics.spacing20, |
| 89 | + ), |
| 90 | + child: SafeArea( |
| 91 | + child: Column( |
| 92 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 93 | + children: [ |
| 94 | + _buildTitle(context), |
| 95 | + const SizedBox(height: Metrics.spacing16), |
| 96 | + _buildDescription(context), |
| 97 | + const Spacer(), |
| 98 | + Row( |
| 99 | + children: [ |
| 100 | + const Spacer(), |
| 101 | + _buildButton(context), |
| 102 | + ], |
| 103 | + ), |
| 104 | + ], |
| 105 | + ), |
| 106 | + ), |
| 107 | + ), |
| 108 | + ], |
| 109 | + ), |
| 110 | + ); |
| 111 | + } |
| 112 | +} |
0 commit comments