Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zamahaka/19bf7d8be61b2f1e411610e63c766e05 to your computer and use it in GitHub Desktop.
Save zamahaka/19bf7d8be61b2f1e411610e63c766e05 to your computer and use it in GitHub Desktop.
Home
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/material.dart';
import 'package:the_house/infrastructure/core/exceptions/no_type_exception.dart';
import 'package:the_house/infrastructure/home_feed/model/chart_data/chart_data.dart';
import 'package:the_house/infrastructure/home_feed/model/content_data/content_data.dart';
import 'package:the_house/infrastructure/home_feed/model/data_data/data_data.dart';
import 'package:the_house/infrastructure/home_feed/model/feedback_data/feedback_data.dart';
import 'package:the_house/infrastructure/home_feed/model/hero_data/hero_data.dart';
import 'package:the_house/presentation/widgets/create_widgets_from_data/widgets/create_chart_widget.dart';
import 'package:the_house/presentation/widgets/create_widgets_from_data/widgets/create_content_widget.dart';
import 'package:the_house/presentation/widgets/create_widgets_from_data/widgets/create_data_widget.dart';
import 'package:the_house/presentation/widgets/create_widgets_from_data/widgets/create_feedback_widget.dart';
import 'package:the_house/presentation/widgets/create_widgets_from_data/widgets/create_hero_widget.dart';
Widget createWidgetFromData(dynamic data) {
var createFunction;
if (data is HeroData) {
createFunction = createHeroWidget;
} else if (data is ContentData) {
createFunction = createContentWidget;
} else if (data is FeedbackData) {
createFunction = createFeedbackWidget;
} else if (data is DataData) {
createFunction = createDataWidget;
} else if (data is ChartData) {
createFunction = createChartWidget;
}
assert(createFunction != null, 'Unsupported data type ${data.toString()}');
if (createFunction != null) {
return createFunction(data);
} else {
FirebaseCrashlytics.instance.recordError(
UnsupportedTypeException(data.toString()),
StackTrace.current,
reason: 'while trying to create widget for type: ${data.toString()}',
);
return SizedBox.shrink();
}
}
import 'package:flutter/material.dart';
import 'package:the_house/infrastructure/home_feed/model/chart_data/chart_data.dart';
import 'package:the_house/infrastructure/home_feed/model/chart_data/models/bar_data/bar_data.dart';
import 'package:the_house/infrastructure/home_feed/model/chart_data/models/spot_data/spot_data.dart';
import 'package:the_house/infrastructure/home_feed/model/chart_data/models/stacked_area_data/stacked_area_data.dart';
import 'package:the_house/infrastructure/home_feed/model/chart_data/models/timed_data/timed_data.dart'
as d;
import 'package:the_house/presentation/core/colors.dart';
import 'package:the_house/presentation/core/constants/dimension.dart';
import 'package:the_house/presentation/core/theme/theme.dart';
import 'package:the_house/presentation/widgets/chart_container/chart_container.dart';
import 'package:the_house/presentation/widgets/charts/house_bar_chart/house_bar_chart.dart';
import 'package:the_house/presentation/widgets/charts/house_line_chart/house_line_chart.dart';
import 'package:the_house/presentation/widgets/charts/house_stacked_area_chart/house_stacked_area_chart.dart';
import 'package:the_house/presentation/widgets/charts/house_timed_data_chart/house_timed_data_chart.dart';
const double _dataChartHeight = 194;
const EdgeInsets _dataChartTitlePadding = EdgeInsets.only(
left: 16,
top: 16,
bottom: 26,
);
const EdgeInsets _dataChartSubTitlePadding = EdgeInsets.only(left: 16);
Widget createChartWidget(ChartData data) => Chart(data: data);
class Chart extends StatelessWidget {
final ChartData data;
const Chart({Key? key, required this.data}) : super(key: key);
@override
Widget build(BuildContext context) {
Widget child;
switch (data.type) {
case ChartDataType.bar:
child = _createBarChart((data.data as List).cast<BarData>());
break;
case ChartDataType.line:
child = _createLineChart((data.data as List).cast<SpotData>());
break;
case ChartDataType.stackedArea:
child = _createStackedAreaChart(
(data.data as List).cast<StackedAreaData>(),
);
break;
case ChartDataType.timed:
child = _createTimedChart((data.data as List).cast<d.TimedData>());
return ChartContainer(
childTop: 0,
title: data.title,
subTitle: data.subtitle ?? '',
titleStyle: context.appTextTheme.h4,
childHeight: _dataChartHeight,
color: AppColors.sage.shade100,
titlePadding: _dataChartTitlePadding,
subTitlePadding: _dataChartSubTitlePadding,
borderRadius: BorderRadius.circular(BORDER_RADIUS),
child: child,
);
}
return ChartContainer(
title: data.title,
subTitle: data.subtitle ?? '',
child: child,
);
}
}
Widget _createTimedChart(List<d.TimedData> spots) => HouseTimedDataChart(
formatLastSpotTooltip: (value) => '${value.toStringAsFixed(0)} h',
spots: spots.map((e) => e.toModel()).toList(),
);
Widget _createBarChart(List<BarData> rods) =>
HouseBarChart(rods: rods.map((e) => e.toModel()).toList());
Widget _createLineChart(List<SpotData> spots) =>
HouseLineChart(spots: spots.map((e) => e.toModel()).toList());
Widget _createStackedAreaChart(List<StackedAreaData> areas) =>
HouseStackedAreaChart(areas: areas.map((e) => e.toModel()).toList());
import 'package:flutter/material.dart';
import 'package:the_house/infrastructure/home_feed/model/content_data/content_data.dart';
import 'package:the_house/presentation/widgets/content_card/content_card.dart';
import 'package:the_house/presentation/widgets/content_card/widgets/icon.dart';
import 'package:the_house/presentation/widgets/content_card/widgets/image.dart';
import 'package:the_house/presentation/widgets/create_widgets_from_data/widgets/get_icon.dart';
Widget createContentWidget(ContentData data) {
final image = data.image == null
? null
: ContentCardImage(
url: data.image!.url,
size: data.size,
);
final iconData = getIconData(data.icon);
final icon = iconData == null ? null : ContentCardIcon(icon: iconData);
return ContentCard(
title: data.title,
subhead: data.subhead,
trailing: image,
leading: icon,
onPressed: data.action == null ? null : () {},
);
}
import 'package:flutter/material.dart';
import 'package:the_house/infrastructure/home_feed/model/data_data/data_data.dart';
import 'package:the_house/infrastructure/home_feed/model/data_data/data_data_variant.dart';
import 'package:the_house/infrastructure/home_feed/model/data_data/data_item/data_item.dart';
import 'package:the_house/presentation/core/colors.dart';
import 'package:the_house/presentation/core/constants/dimension.dart';
import 'package:the_house/presentation/widgets/create_widgets_from_data/widgets/get_icon.dart';
import 'package:the_house/presentation/widgets/data_card/data_card.dart';
import 'package:the_house/presentation/widgets/data_card/widgets/icon.dart';
import 'package:the_house/presentation/widgets/data_card/widgets/progress.dart';
const _GRID_VIEW_CHILD_ASPECT_RATIO = 1.3;
Widget createDataWidget(DataData data) {
final children = List.generate(
data.items.length,
(index) => _createCardItem(
index: index,
item: data.items[index],
variant: data.variant,
),
);
switch (data.variant) {
case DataDataVarial.validationSmall:
case DataDataVarial.previewSmall:
return GridView.count(
padding: EdgeInsets.zero,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
crossAxisCount: 2,
mainAxisSpacing: MEDIUM_SPACE,
crossAxisSpacing: LIGHT_SPACE / 2,
childAspectRatio: _GRID_VIEW_CHILD_ASPECT_RATIO,
children: children,
);
case DataDataVarial.validationLarge:
case DataDataVarial.previewLarge:
return Column(
children: children
.map(
(child) => Padding(
padding: const EdgeInsets.only(top: LIGHT_SPACE / 2),
child: child,
),
)
.toList(),
);
default:
throw ArgumentError(
"Unsupported enum in createDataWidget func: "
"${data.variant}",
);
}
}
DataCard _createCardItem({
required int index,
required DataItem item,
required DataDataVarial variant,
}) {
final iconData = getIconData(item.icon);
final icon = iconData == null ? null : DataCardIcon(icon: iconData);
final progress = item.progress == null
? null
: DataCardProgress(progress: item.progress!.progress);
return DataCard(
title: item.title,
subtitle: item.body,
leading: progress ?? icon ?? DataCardProgress(progress: null),
style: variant,
backgroundColor: ColorCombinations.dataList[index].background,
onPressed: item.action == null ? null : () {},
);
}
import 'package:flutter/material.dart';
import 'package:the_house/infrastructure/home_feed/model/feedback_data/feedback_data.dart';
import 'package:the_house/presentation/widgets/create_widgets_from_data/widgets/get_icon.dart';
import 'package:the_house/presentation/widgets/feedback_card/feedback_card.dart';
import 'package:the_house/presentation/widgets/feedback_card/widgets/icon.dart';
Widget createFeedbackWidget(FeedbackData data) {
final iconData = getIconData(data.icon);
final icon = iconData == null ? null : FeedbackCardIcon(icon: iconData);
return FeedbackCard(
title: data.title,
subtitle: data.body,
leading: icon,
footer: null,
onPressed: data.action == null ? null : () {},
);
}
import 'package:flutter/material.dart';
import 'package:the_house/infrastructure/home_feed/model/hero_data/hero_data.dart';
import 'package:the_house/presentation/widgets/hero_card/hero_card.dart';
import 'package:the_house/presentation/widgets/hero_card/widgets/footer_texture.dart';
import 'package:the_house/presentation/widgets/hero_card/widgets/image.dart';
import 'package:the_house/presentation/widgets/hero_card/widgets/progress.dart';
Widget createHeroWidget(HeroData data) {
final image = data.image == null ? null : HeroCardImage(url: data.image!.url);
final progress = data.progress == null
? null
: HeroCardProgress(
title: data.progress!.title,
progress: data.progress!.progress,
);
return HeroCard(
title: data.title,
meta: data.meta,
subtitle: data.body,
footer: data.includeFooter ? FooterTexture() : null,
header: progress ?? image,
);
}
import 'package:flutter/material.dart';
import 'package:the_house/presentation/app_icons.dart';
const iconsMap = <String, IconData>{
'icon-face-smile': AppIcons.smile,
'icon-face-speechless': AppIcons.speechless,
'data-trend-up': AppIcons.data_trend_up,
'data-trend-down': AppIcons.data_trend_down,
'data-trend-flat': AppIcons.data_trend_flat,
};
IconData? getIconData(String? icon) {
if (icon == null) {
return null;
} else {
final data = iconsMap[icon];
return data == null ? null : data;
}
}
part of 'home.dart';
const WEARABLE_ICON_SIZE = 45.0;
const TEXTURE_RADIUS = 0.85;
const TEXTURE_SCALE = 1.4;
import 'package:dartx/dartx.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:intl/intl.dart';
import 'package:the_house/bloc/home/home_bloc.dart';
import 'package:the_house/infrastructure/home_feed/model/feed_item/feed_item.dart';
import 'package:the_house/infrastructure/home_feed/model/home_feed.dart';
import 'package:the_house/presentation/core/constants/dimension.dart';
import 'package:the_house/presentation/core/constants/textures.dart';
import 'package:the_house/presentation/core/extensions/l10n.dart';
import 'package:the_house/presentation/core/theme/theme.dart';
import 'package:the_house/presentation/core/utils/divide_widgets.dart';
import 'package:the_house/presentation/widgets/app_texture.dart';
import 'package:the_house/presentation/widgets/blur.dart';
import 'package:the_house/presentation/widgets/content_card/content_card_shimmer.dart';
import 'package:the_house/presentation/widgets/create_widgets_from_data/create_widget_from_data.dart';
import 'package:the_house/presentation/widgets/data_card/data_card_shimmer.dart';
import 'package:the_house/presentation/widgets/feedback_card/feedback_card_shimmer.dart';
import 'package:the_house/presentation/widgets/gradient/app_gradients.dart';
import 'package:the_house/presentation/widgets/gradient/background_gradient.dart';
import 'package:the_house/presentation/widgets/gradient/transform_gradient.dart';
import 'package:the_house/presentation/widgets/hero_card/hero_card_shimmer.dart';
import 'package:the_house/presentation/widgets/info_text/info_text.dart';
part 'dimensions.dart';
part 'home_page_background.dart';
part 'widgets/loading.dart';
class HomePage extends StatelessWidget {
final EdgeInsets listPadding;
const HomePage({
Key? key,
this.listPadding = EdgeInsets.zero,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
padding: _pagePadding,
child: BlocBuilder<HomeBloc, HomeState>(
builder: (context, state) {
return state.when(
loading: () => _LoadingBody(),
showFailure: _showError,
showHomeFeed: (feed) => _buildHomeFeed(context, feed),
);
},
),
);
}
EdgeInsets get _pagePadding =>
const EdgeInsets.symmetric(
horizontal: LIGHT_SPACE,
vertical: 166,
) +
listPadding;
Widget _showError(failure) => Text(
failure.map(
unexpected: (_) =>
'Unexpected error occured while deleting, please contact support.',
insufficientPermission: (_) => 'Insufficient permissions ❌',
),
);
Widget _buildHomeFeed(BuildContext context, HomeFeed feed) => Column(
children: [
const _TextInfo(),
if (feed.news != null)
...divideWidgets(widgets: _convertToWidgets(feed.news!)),
if (feed.recovery != null) ...[
const _YourActivityText(),
...divideWidgets(widgets: _convertToWidgets(feed.recovery!)),
],
],
);
List<Widget> _convertToWidgets(List<FeedItem?> items) => items
.filterNotNull()
.map((item) => item.data)
.map(createWidgetFromData)
.toList();
}
class _TextInfo extends StatelessWidget {
const _TextInfo({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return InfoTextSkeleton(
padding: const EdgeInsets.fromLTRB(
LIGHT_SPACE,
LIGHT_SPACE,
LIGHT_SPACE,
MEDIUM_SPACE * 5,
),
title: Text(
DateFormat('EEEE, MMM dd').format(DateTime(2021, 1, 25)),
style: AppTheme.of(context).textTheme.h4,
),
subtitle: Text(
'Good morning, Felix',
style: AppTheme.of(context).textTheme.h1,
),
);
}
}
class _YourActivityText extends StatelessWidget {
const _YourActivityText({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(
top: LIGHT_SPACE * 3,
bottom: LIGHT_SPACE * 2,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: LIGHT_SPACE),
child: Text(
context.s.yourRecovery.toUpperCase(),
style: context.appTheme.textTheme.sectionHeadline,
),
),
const SizedBox(height: LIGHT_SPACE),
Divider(thickness: 1),
],
),
);
}
}
import 'package:flutter/foundation.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import 'package:the_house/bloc/core/subscription_bloc.dart';
import 'package:the_house/domain/home-feed/home_feed_failure.dart';
import 'package:the_house/infrastructure/home_feed/home_feed_repository.dart';
import 'package:the_house/infrastructure/home_feed/model/home_feed.dart';
part 'home_bloc.freezed.dart';
part 'home_event.dart';
part 'home_state.dart';
@injectable
class HomeBloc extends Bloc<HomeEvent, HomeState>
with SubscriptionBloc<HomeEvent, HomeState> {
final HomeFeedRepository _homeFeedRepository;
HomeBloc(this._homeFeedRepository) : super(_Loading());
@override
Stream<HomeState> mapEventToState(HomeEvent event) async* {
yield* event.when(
initial: _mapInitialState,
updateFeed: _mapUpdateHomeFeed,
);
}
Stream<HomeState> _mapInitialState() async* {
await Future.delayed(Duration(seconds: 1));
yield _homeFeedRepository.watch().fold(
(failure) => _ShowFailure(failure),
(homeFeedStream) {
subscription = homeFeedStream.listen(
(homeFeed) => add(_UpdateFeed(homeFeed)),
);
return _Loading();
},
);
}
Stream<HomeState> _mapUpdateHomeFeed(HomeFeed homeFeed) async* {
yield _ShowHomeFeed(homeFeed);
}
}
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides
part of 'home_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
/// @nodoc
class _$HomeEventTearOff {
const _$HomeEventTearOff();
_Initial initial() {
return const _Initial();
}
_UpdateFeed updateFeed(HomeFeed homeFeed) {
return _UpdateFeed(
homeFeed,
);
}
}
/// @nodoc
const $HomeEvent = _$HomeEventTearOff();
/// @nodoc
mixin _$HomeEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function(HomeFeed homeFeed) updateFeed,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function(HomeFeed homeFeed)? updateFeed,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_UpdateFeed value) updateFeed,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_UpdateFeed value)? updateFeed,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $HomeEventCopyWith<$Res> {
factory $HomeEventCopyWith(HomeEvent value, $Res Function(HomeEvent) then) =
_$HomeEventCopyWithImpl<$Res>;
}
/// @nodoc
class _$HomeEventCopyWithImpl<$Res> implements $HomeEventCopyWith<$Res> {
_$HomeEventCopyWithImpl(this._value, this._then);
final HomeEvent _value;
// ignore: unused_field
final $Res Function(HomeEvent) _then;
}
/// @nodoc
abstract class _$InitialCopyWith<$Res> {
factory _$InitialCopyWith(_Initial value, $Res Function(_Initial) then) =
__$InitialCopyWithImpl<$Res>;
}
/// @nodoc
class __$InitialCopyWithImpl<$Res> extends _$HomeEventCopyWithImpl<$Res>
implements _$InitialCopyWith<$Res> {
__$InitialCopyWithImpl(_Initial _value, $Res Function(_Initial) _then)
: super(_value, (v) => _then(v as _Initial));
@override
_Initial get _value => super._value as _Initial;
}
/// @nodoc
class _$_Initial with DiagnosticableTreeMixin implements _Initial {
const _$_Initial();
@override
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
return 'HomeEvent.initial()';
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties..add(DiagnosticsProperty('type', 'HomeEvent.initial'));
}
@override
bool operator ==(dynamic other) {
return identical(this, other) || (other is _Initial);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function(HomeFeed homeFeed) updateFeed,
}) {
return initial();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function(HomeFeed homeFeed)? updateFeed,
required TResult orElse(),
}) {
if (initial != null) {
return initial();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_UpdateFeed value) updateFeed,
}) {
return initial(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_UpdateFeed value)? updateFeed,
required TResult orElse(),
}) {
if (initial != null) {
return initial(this);
}
return orElse();
}
}
abstract class _Initial implements HomeEvent {
const factory _Initial() = _$_Initial;
}
/// @nodoc
abstract class _$UpdateFeedCopyWith<$Res> {
factory _$UpdateFeedCopyWith(
_UpdateFeed value, $Res Function(_UpdateFeed) then) =
__$UpdateFeedCopyWithImpl<$Res>;
$Res call({HomeFeed homeFeed});
$HomeFeedCopyWith<$Res> get homeFeed;
}
/// @nodoc
class __$UpdateFeedCopyWithImpl<$Res> extends _$HomeEventCopyWithImpl<$Res>
implements _$UpdateFeedCopyWith<$Res> {
__$UpdateFeedCopyWithImpl(
_UpdateFeed _value, $Res Function(_UpdateFeed) _then)
: super(_value, (v) => _then(v as _UpdateFeed));
@override
_UpdateFeed get _value => super._value as _UpdateFeed;
@override
$Res call({
Object? homeFeed = freezed,
}) {
return _then(_UpdateFeed(
homeFeed == freezed
? _value.homeFeed
: homeFeed // ignore: cast_nullable_to_non_nullable
as HomeFeed,
));
}
@override
$HomeFeedCopyWith<$Res> get homeFeed {
return $HomeFeedCopyWith<$Res>(_value.homeFeed, (value) {
return _then(_value.copyWith(homeFeed: value));
});
}
}
/// @nodoc
class _$_UpdateFeed with DiagnosticableTreeMixin implements _UpdateFeed {
const _$_UpdateFeed(this.homeFeed);
@override
final HomeFeed homeFeed;
@override
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
return 'HomeEvent.updateFeed(homeFeed: $homeFeed)';
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('type', 'HomeEvent.updateFeed'))
..add(DiagnosticsProperty('homeFeed', homeFeed));
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other is _UpdateFeed &&
(identical(other.homeFeed, homeFeed) ||
const DeepCollectionEquality()
.equals(other.homeFeed, homeFeed)));
}
@override
int get hashCode =>
runtimeType.hashCode ^ const DeepCollectionEquality().hash(homeFeed);
@JsonKey(ignore: true)
@override
_$UpdateFeedCopyWith<_UpdateFeed> get copyWith =>
__$UpdateFeedCopyWithImpl<_UpdateFeed>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function(HomeFeed homeFeed) updateFeed,
}) {
return updateFeed(homeFeed);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function(HomeFeed homeFeed)? updateFeed,
required TResult orElse(),
}) {
if (updateFeed != null) {
return updateFeed(homeFeed);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_UpdateFeed value) updateFeed,
}) {
return updateFeed(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_UpdateFeed value)? updateFeed,
required TResult orElse(),
}) {
if (updateFeed != null) {
return updateFeed(this);
}
return orElse();
}
}
abstract class _UpdateFeed implements HomeEvent {
const factory _UpdateFeed(HomeFeed homeFeed) = _$_UpdateFeed;
HomeFeed get homeFeed => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
_$UpdateFeedCopyWith<_UpdateFeed> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
class _$HomeStateTearOff {
const _$HomeStateTearOff();
_Loading loading() {
return const _Loading();
}
_ShowFailure showFailure(HomeFeedFailure failure) {
return _ShowFailure(
failure,
);
}
_ShowHomeFeed showHomeFeed(HomeFeed homeFeed) {
return _ShowHomeFeed(
homeFeed,
);
}
}
/// @nodoc
const $HomeState = _$HomeStateTearOff();
/// @nodoc
mixin _$HomeState {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() loading,
required TResult Function(HomeFeedFailure failure) showFailure,
required TResult Function(HomeFeed homeFeed) showHomeFeed,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? loading,
TResult Function(HomeFeedFailure failure)? showFailure,
TResult Function(HomeFeed homeFeed)? showHomeFeed,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Loading value) loading,
required TResult Function(_ShowFailure value) showFailure,
required TResult Function(_ShowHomeFeed value) showHomeFeed,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Loading value)? loading,
TResult Function(_ShowFailure value)? showFailure,
TResult Function(_ShowHomeFeed value)? showHomeFeed,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $HomeStateCopyWith<$Res> {
factory $HomeStateCopyWith(HomeState value, $Res Function(HomeState) then) =
_$HomeStateCopyWithImpl<$Res>;
}
/// @nodoc
class _$HomeStateCopyWithImpl<$Res> implements $HomeStateCopyWith<$Res> {
_$HomeStateCopyWithImpl(this._value, this._then);
final HomeState _value;
// ignore: unused_field
final $Res Function(HomeState) _then;
}
/// @nodoc
abstract class _$LoadingCopyWith<$Res> {
factory _$LoadingCopyWith(_Loading value, $Res Function(_Loading) then) =
__$LoadingCopyWithImpl<$Res>;
}
/// @nodoc
class __$LoadingCopyWithImpl<$Res> extends _$HomeStateCopyWithImpl<$Res>
implements _$LoadingCopyWith<$Res> {
__$LoadingCopyWithImpl(_Loading _value, $Res Function(_Loading) _then)
: super(_value, (v) => _then(v as _Loading));
@override
_Loading get _value => super._value as _Loading;
}
/// @nodoc
class _$_Loading with DiagnosticableTreeMixin implements _Loading {
const _$_Loading();
@override
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
return 'HomeState.loading()';
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties..add(DiagnosticsProperty('type', 'HomeState.loading'));
}
@override
bool operator ==(dynamic other) {
return identical(this, other) || (other is _Loading);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() loading,
required TResult Function(HomeFeedFailure failure) showFailure,
required TResult Function(HomeFeed homeFeed) showHomeFeed,
}) {
return loading();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? loading,
TResult Function(HomeFeedFailure failure)? showFailure,
TResult Function(HomeFeed homeFeed)? showHomeFeed,
required TResult orElse(),
}) {
if (loading != null) {
return loading();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Loading value) loading,
required TResult Function(_ShowFailure value) showFailure,
required TResult Function(_ShowHomeFeed value) showHomeFeed,
}) {
return loading(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Loading value)? loading,
TResult Function(_ShowFailure value)? showFailure,
TResult Function(_ShowHomeFeed value)? showHomeFeed,
required TResult orElse(),
}) {
if (loading != null) {
return loading(this);
}
return orElse();
}
}
abstract class _Loading implements HomeState {
const factory _Loading() = _$_Loading;
}
/// @nodoc
abstract class _$ShowFailureCopyWith<$Res> {
factory _$ShowFailureCopyWith(
_ShowFailure value, $Res Function(_ShowFailure) then) =
__$ShowFailureCopyWithImpl<$Res>;
$Res call({HomeFeedFailure failure});
$HomeFeedFailureCopyWith<$Res> get failure;
}
/// @nodoc
class __$ShowFailureCopyWithImpl<$Res> extends _$HomeStateCopyWithImpl<$Res>
implements _$ShowFailureCopyWith<$Res> {
__$ShowFailureCopyWithImpl(
_ShowFailure _value, $Res Function(_ShowFailure) _then)
: super(_value, (v) => _then(v as _ShowFailure));
@override
_ShowFailure get _value => super._value as _ShowFailure;
@override
$Res call({
Object? failure = freezed,
}) {
return _then(_ShowFailure(
failure == freezed
? _value.failure
: failure // ignore: cast_nullable_to_non_nullable
as HomeFeedFailure,
));
}
@override
$HomeFeedFailureCopyWith<$Res> get failure {
return $HomeFeedFailureCopyWith<$Res>(_value.failure, (value) {
return _then(_value.copyWith(failure: value));
});
}
}
/// @nodoc
class _$_ShowFailure with DiagnosticableTreeMixin implements _ShowFailure {
const _$_ShowFailure(this.failure);
@override
final HomeFeedFailure failure;
@override
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
return 'HomeState.showFailure(failure: $failure)';
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('type', 'HomeState.showFailure'))
..add(DiagnosticsProperty('failure', failure));
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other is _ShowFailure &&
(identical(other.failure, failure) ||
const DeepCollectionEquality().equals(other.failure, failure)));
}
@override
int get hashCode =>
runtimeType.hashCode ^ const DeepCollectionEquality().hash(failure);
@JsonKey(ignore: true)
@override
_$ShowFailureCopyWith<_ShowFailure> get copyWith =>
__$ShowFailureCopyWithImpl<_ShowFailure>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() loading,
required TResult Function(HomeFeedFailure failure) showFailure,
required TResult Function(HomeFeed homeFeed) showHomeFeed,
}) {
return showFailure(failure);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? loading,
TResult Function(HomeFeedFailure failure)? showFailure,
TResult Function(HomeFeed homeFeed)? showHomeFeed,
required TResult orElse(),
}) {
if (showFailure != null) {
return showFailure(failure);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Loading value) loading,
required TResult Function(_ShowFailure value) showFailure,
required TResult Function(_ShowHomeFeed value) showHomeFeed,
}) {
return showFailure(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Loading value)? loading,
TResult Function(_ShowFailure value)? showFailure,
TResult Function(_ShowHomeFeed value)? showHomeFeed,
required TResult orElse(),
}) {
if (showFailure != null) {
return showFailure(this);
}
return orElse();
}
}
abstract class _ShowFailure implements HomeState {
const factory _ShowFailure(HomeFeedFailure failure) = _$_ShowFailure;
HomeFeedFailure get failure => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
_$ShowFailureCopyWith<_ShowFailure> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class _$ShowHomeFeedCopyWith<$Res> {
factory _$ShowHomeFeedCopyWith(
_ShowHomeFeed value, $Res Function(_ShowHomeFeed) then) =
__$ShowHomeFeedCopyWithImpl<$Res>;
$Res call({HomeFeed homeFeed});
$HomeFeedCopyWith<$Res> get homeFeed;
}
/// @nodoc
class __$ShowHomeFeedCopyWithImpl<$Res> extends _$HomeStateCopyWithImpl<$Res>
implements _$ShowHomeFeedCopyWith<$Res> {
__$ShowHomeFeedCopyWithImpl(
_ShowHomeFeed _value, $Res Function(_ShowHomeFeed) _then)
: super(_value, (v) => _then(v as _ShowHomeFeed));
@override
_ShowHomeFeed get _value => super._value as _ShowHomeFeed;
@override
$Res call({
Object? homeFeed = freezed,
}) {
return _then(_ShowHomeFeed(
homeFeed == freezed
? _value.homeFeed
: homeFeed // ignore: cast_nullable_to_non_nullable
as HomeFeed,
));
}
@override
$HomeFeedCopyWith<$Res> get homeFeed {
return $HomeFeedCopyWith<$Res>(_value.homeFeed, (value) {
return _then(_value.copyWith(homeFeed: value));
});
}
}
/// @nodoc
class _$_ShowHomeFeed with DiagnosticableTreeMixin implements _ShowHomeFeed {
const _$_ShowHomeFeed(this.homeFeed);
@override
final HomeFeed homeFeed;
@override
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
return 'HomeState.showHomeFeed(homeFeed: $homeFeed)';
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('type', 'HomeState.showHomeFeed'))
..add(DiagnosticsProperty('homeFeed', homeFeed));
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other is _ShowHomeFeed &&
(identical(other.homeFeed, homeFeed) ||
const DeepCollectionEquality()
.equals(other.homeFeed, homeFeed)));
}
@override
int get hashCode =>
runtimeType.hashCode ^ const DeepCollectionEquality().hash(homeFeed);
@JsonKey(ignore: true)
@override
_$ShowHomeFeedCopyWith<_ShowHomeFeed> get copyWith =>
__$ShowHomeFeedCopyWithImpl<_ShowHomeFeed>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() loading,
required TResult Function(HomeFeedFailure failure) showFailure,
required TResult Function(HomeFeed homeFeed) showHomeFeed,
}) {
return showHomeFeed(homeFeed);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? loading,
TResult Function(HomeFeedFailure failure)? showFailure,
TResult Function(HomeFeed homeFeed)? showHomeFeed,
required TResult orElse(),
}) {
if (showHomeFeed != null) {
return showHomeFeed(homeFeed);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Loading value) loading,
required TResult Function(_ShowFailure value) showFailure,
required TResult Function(_ShowHomeFeed value) showHomeFeed,
}) {
return showHomeFeed(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Loading value)? loading,
TResult Function(_ShowFailure value)? showFailure,
TResult Function(_ShowHomeFeed value)? showHomeFeed,
required TResult orElse(),
}) {
if (showHomeFeed != null) {
return showHomeFeed(this);
}
return orElse();
}
}
abstract class _ShowHomeFeed implements HomeState {
const factory _ShowHomeFeed(HomeFeed homeFeed) = _$_ShowHomeFeed;
HomeFeed get homeFeed => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
_$ShowHomeFeedCopyWith<_ShowHomeFeed> get copyWith =>
throw _privateConstructorUsedError;
}
part of 'home_bloc.dart';
@freezed
class HomeEvent with _$HomeEvent {
const factory HomeEvent.initial() = _Initial;
const factory HomeEvent.updateFeed(HomeFeed homeFeed) = _UpdateFeed;
}
part of 'home.dart';
class HomePageBackground extends StatelessWidget {
final Widget child;
const HomePageBackground({
Key? key,
required this.child,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Stack(
children: [
SizedBox(
height: MediaQuery.of(context).size.height,
child: TextureStack(
background: Stack(
children: [
AdaptiveGradient(
colors: AppGradients.homePage.colors,
stops: AppGradients.homePage.stops,
),
Blur(),
],
),
texture: const _Texture(),
),
),
child,
],
);
}
}
class _Texture extends StatelessWidget {
const _Texture({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ShaderMask(
shaderCallback: (rect) => RadialGradient(
center: Alignment.topLeft,
radius: TEXTURE_RADIUS,
transform: const TransformGradient(scaleY: TEXTURE_SCALE),
colors: const [Colors.black, Colors.transparent],
stops: const [0.6, 1.0],
).createShader(rect),
blendMode: BlendMode.dstIn,
child: Image.asset(
Textures.grainy4,
color: Colors.white,
fit: BoxFit.cover,
),
);
}
}
part of 'home_bloc.dart';
@freezed
class HomeState with _$HomeState {
const factory HomeState.loading() = _Loading;
const factory HomeState.showFailure(HomeFeedFailure failure) = _ShowFailure;
const factory HomeState.showHomeFeed(HomeFeed homeFeed) = _ShowHomeFeed;
}
part of '../home.dart';
class _LoadingBody extends StatelessWidget {
const _LoadingBody({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_TextInfo(),
HeroCardShimmer(),
const SizedBox(height: LIGHT_SPACE / 2),
FeedbackCardShimmer(),
const SizedBox(height: LIGHT_SPACE / 2),
_YourActivityText(),
ContentCardShimmer(),
const SizedBox(height: LIGHT_SPACE / 2),
Row(
children: [
Expanded(child: DataCardShimmer()),
const SizedBox(width: LIGHT_SPACE / 2),
Expanded(child: DataCardShimmer()),
],
),
const SizedBox(height: LIGHT_SPACE / 2),
ContentCardShimmer(),
const SizedBox(height: LIGHT_SPACE / 2),
HeroCardShimmer(),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment