wonders/lib/ui/screens/wonder_events/wonder_events.dart

142 lines
4.7 KiB
Dart
Raw Normal View History

2022-08-29 20:38:28 -06:00
import 'package:wonders/common_libs.dart';
import 'package:wonders/logic/common/string_utils.dart';
import 'package:wonders/logic/data/wonder_data.dart';
import 'package:wonders/ui/common/app_backdrop.dart';
import 'package:wonders/ui/common/app_icons.dart';
import 'package:wonders/ui/common/centered_box.dart';
2022-12-20 10:23:20 -07:00
import 'package:wonders/ui/common/controls/app_header.dart';
2022-08-29 20:38:28 -06:00
import 'package:wonders/ui/common/curved_clippers.dart';
import 'package:wonders/ui/common/hidden_collectible.dart';
import 'package:wonders/ui/common/list_gradient.dart';
import 'package:wonders/ui/common/themed_text.dart';
import 'package:wonders/ui/common/timeline_event_card.dart';
import 'package:wonders/ui/common/wonders_timeline_builder.dart';
import 'package:wonders/ui/wonder_illustrations/common/wonder_title_text.dart';
part 'widgets/_events_list.dart';
part 'widgets/_timeline_btn.dart';
part 'widgets/_wonder_image_with_timeline.dart';
2022-08-29 20:38:28 -06:00
//TODO: Maintain scroll position when switching from portrait to landscape
2022-08-29 20:38:28 -06:00
class WonderEvents extends StatelessWidget {
WonderEvents({Key? key, required this.type}) : super(key: key);
final WonderType type;
late final _data = wondersLogic.getData(type);
@override
Widget build(BuildContext context) {
void handleTimelineBtnPressed() => context.push(ScreenPaths.timeline(type));
return LayoutBuilder(builder: (context, constraints) {
2022-08-29 20:38:28 -06:00
return Container(
color: $styles.colors.black,
child: SafeArea(
bottom: false,
child: Stack(
children: [
/// Main view switches between portrait and landscape views
Positioned.fill(
top: $styles.insets.lg,
2022-12-20 10:23:20 -07:00
child: context.isLandscape ? _buildLandscape(context) : _buildPortrait(),
),
2022-12-20 10:23:20 -07:00
/// Header w/ TimelineBtn
TopCenter(
child: AppHeader(
showBackBtn: false,
isTransparent: true,
trailing: (_) => CircleIconBtn(
icon: AppIcons.timeline,
onPressed: handleTimelineBtnPressed,
2022-12-20 10:23:20 -07:00
semanticLabel: $strings.eventsListButtonOpenGlobal),
),
),
],
),
),
);
});
}
/// Landscape layout is a row, with the WonderImage on left and EventsList on the right
2022-12-20 10:23:20 -07:00
Widget _buildLandscape(BuildContext context) {
return Row(
children: [
/// WonderImage w/ Timeline btn
Expanded(
child: CenteredBox(
width: $styles.sizes.maxContentWidth3,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Gap($styles.insets.lg),
2022-12-20 10:23:20 -07:00
Expanded(
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
_WonderImageWithTimeline(data: _data, height: min(500, context.heightPx - 300)),
Gap($styles.insets.lg),
SizedBox(width: 300, child: _TimelineBtn(type: type)),
],
),
),
),
Gap($styles.insets.lg),
],
),
2022-08-29 20:38:28 -06:00
),
),
/// EventsList
Expanded(
child: CenteredBox(
2022-12-20 10:23:20 -07:00
width: $styles.sizes.maxContentWidth2,
child: _EventsList(
data: _data,
topHeight: 100,
blurOnScroll: false,
),
),
),
],
);
}
/// Portrait layout is a stack with the EventsList scrolling overtop of the WonderImage
Widget _buildPortrait() {
return LayoutBuilder(builder: (_, constraints) {
double topHeight = max(constraints.maxHeight * .55, 200);
return CenteredBox(
width: $styles.sizes.maxContentWidth3,
child: Stack(
children: [
/// Top content, sits underneath scrolling list
_WonderImageWithTimeline(height: topHeight, data: _data),
/// EventsList + TimelineBtn
Column(
children: [
Expanded(
/// List
child: _EventsList(
data: _data,
topHeight: topHeight,
blurOnScroll: true,
showTopGradient: false,
),
),
Gap($styles.insets.lg),
/// Btn
_TimelineBtn(type: _data.type, width: $styles.sizes.maxContentWidth3),
Gap($styles.insets.xl),
],
),
],
),
2022-08-29 20:38:28 -06:00
);
});
}
}