2022-08-29 20:38:28 -06:00
import ' package:wonders/common_libs.dart ' ;
2023-01-23 09:07:30 -07:00
import ' package:wonders/logic/common/platform_info.dart ' ;
2022-08-29 20:38:28 -06:00
import ' package:wonders/logic/common/string_utils.dart ' ;
import ' package:wonders/logic/data/wonder_data.dart ' ;
import ' package:wonders/ui/common/app_backdrop.dart ' ;
2022-11-14 11:59:45 -07:00
import ' package:wonders/ui/common/app_icons.dart ' ;
2022-11-14 15:36:34 -07:00
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 ' ;
2022-11-14 11:59:45 -07:00
part ' widgets/_timeline_btn.dart ' ;
part ' widgets/_wonder_image_with_timeline.dart ' ;
2022-08-29 20:38:28 -06:00
2023-04-18 11:03:17 -06:00
class WonderEvents extends StatefulWidget {
2024-02-20 13:56:39 -08:00
const WonderEvents ( { super . key , required this . type , this . contentPadding = EdgeInsets . zero } ) ;
2022-08-29 20:38:28 -06:00
final WonderType type ;
2023-04-18 11:47:03 -06:00
final EdgeInsets contentPadding ;
2023-04-18 11:03:17 -06:00
@ override
State < WonderEvents > createState ( ) = > _WonderEventsState ( ) ;
}
class _WonderEventsState extends State < WonderEvents > {
late final _data = wondersLogic . getData ( widget . type ) ;
final _eventsListKey = GlobalKey < _EventsListState > ( ) ;
2023-02-16 10:02:34 -07:00
double _scrollPos = 0 ;
2023-04-18 11:03:17 -06:00
2023-02-16 10:02:34 -07:00
void _handleScroll ( double pos ) = > _scrollPos = pos ;
2022-08-29 20:38:28 -06:00
@ override
Widget build ( BuildContext context ) {
2024-01-16 17:00:40 -07:00
void handleTimelineBtnPressed ( ) = > context . go ( ScreenPaths . timeline ( widget . type ) ) ;
2023-01-23 09:07:30 -07:00
// Main view content switches between 1 and 2 column layouts
2023-01-25 13:36:58 -07:00
// On mobile, use the 2 column layout on screens close to landscape (>.85). This is primarily an optimization for foldable devices which have square-ish dimensions when opened.
2023-01-23 09:07:30 -07:00
final twoColumnAspect = PlatformInfo . isMobile ? . 85 : 1 ;
bool useTwoColumnLayout = context . mq . size . aspectRatio > twoColumnAspect ;
2022-11-14 11:59:45 -07:00
return LayoutBuilder ( builder: ( context , constraints ) {
2022-08-29 20:38:28 -06:00
return Container (
color: $styles . colors . black ,
child: SafeArea (
bottom: false ,
2022-11-14 11:59:45 -07:00
child: Stack (
children: [
2023-01-23 09:07:30 -07:00
/// Main view
2022-11-14 11:59:45 -07:00
Positioned . fill (
2023-01-04 22:13:26 -07:00
top: $styles . insets . sm ,
2023-04-18 11:47:03 -06:00
child: Padding (
padding: widget . contentPadding ,
child: useTwoColumnLayout ? _buildTwoColumn ( context ) : _buildSingleColumn ( ) ,
) ,
2022-11-14 11:59:45 -07:00
) ,
2022-11-14 14:27:17 -07:00
2022-12-20 10:23:20 -07:00
/// Header w/ TimelineBtn
TopCenter (
child: AppHeader (
showBackBtn: false ,
isTransparent: true ,
trailing: ( _ ) = > CircleIconBtn (
2022-11-14 11:59:45 -07:00
icon: AppIcons . timeline ,
onPressed: handleTimelineBtnPressed ,
2022-12-20 10:23:20 -07:00
semanticLabel: $strings . eventsListButtonOpenGlobal ) ,
) ,
) ,
2022-11-14 11:59:45 -07:00
] ,
) ,
) ,
) ;
} ) ;
}
2022-11-14 14:27:17 -07:00
/// Landscape layout is a row, with the WonderImage on left and EventsList on the right
2023-01-23 09:07:30 -07:00
Widget _buildTwoColumn ( BuildContext context ) {
2023-04-27 11:20:55 -06:00
final double timelineImageSize = ( context . heightPx - 350 ) . clamp ( 200 , 500 ) ;
2023-04-18 10:43:21 -06:00
return Padding (
2023-05-10 14:25:56 -06:00
padding: EdgeInsets . symmetric ( vertical: $styles . insets . lg , horizontal: $styles . insets . sm ) ,
2023-04-18 10:43:21 -06:00
child: Row (
children: [
/// WonderImage w/ Timeline btn
Expanded (
child: CenteredBox (
width: $styles . sizes . maxContentWidth3 ,
2023-04-27 11:20:55 -06:00
child: Padding (
padding: EdgeInsets . symmetric ( vertical: $styles . insets . lg ) ,
child: Column (
mainAxisSize: MainAxisSize . min ,
children: [
_WonderImageWithTimeline ( data: _data , height: timelineImageSize ) ,
Gap ( $styles . insets . lg ) ,
SizedBox ( width: 400 , child: _TimelineBtn ( type: widget . type ) ) ,
] ,
) ,
2023-04-18 10:43:21 -06:00
) ,
2022-10-07 11:54:32 -06:00
) ,
2022-08-29 20:38:28 -06:00
) ,
2022-11-14 11:59:45 -07:00
2023-04-18 10:43:21 -06:00
/// EventsList
Expanded (
child: CenteredBox (
width: $styles . sizes . maxContentWidth2 ,
child: _EventsList (
2023-04-18 11:03:17 -06:00
key: _eventsListKey ,
2023-04-18 10:43:21 -06:00
data: _data ,
topHeight: 100 ,
blurOnScroll: false ,
onScroll: _handleScroll ,
initialScrollOffset: _scrollPos ,
) ,
2022-11-14 11:59:45 -07:00
) ,
) ,
2023-04-18 10:43:21 -06:00
] ,
) ,
2022-11-14 11:59:45 -07:00
) ;
}
2022-11-14 14:27:17 -07:00
/// Portrait layout is a stack with the EventsList scrolling overtop of the WonderImage
2023-01-23 09:07:30 -07:00
Widget _buildSingleColumn ( ) {
2022-11-14 11:59:45 -07:00
return LayoutBuilder ( builder: ( _ , constraints ) {
double topHeight = max ( constraints . maxHeight * . 55 , 200 ) ;
2022-11-14 15:36:34 -07:00
return CenteredBox (
2023-01-04 22:13:26 -07:00
width: $styles . sizes . maxContentWidth2 ,
2022-11-14 15:36:34 -07:00
child: Stack (
children: [
/// Top content, sits underneath scrolling list
_WonderImageWithTimeline ( height: topHeight , data: _data ) ,
2022-11-14 11:59:45 -07:00
2022-11-14 15:36:34 -07:00
/// EventsList + TimelineBtn
Column (
children: [
Expanded (
2023-04-18 11:03:17 -06:00
/// EventsList
2022-11-14 15:36:34 -07:00
child: _EventsList (
2023-04-18 11:03:17 -06:00
key: _eventsListKey ,
2022-11-14 15:36:34 -07:00
data: _data ,
topHeight: topHeight ,
blurOnScroll: true ,
showTopGradient: false ,
2023-02-16 10:02:34 -07:00
onScroll: _handleScroll ,
initialScrollOffset: _scrollPos ,
2022-11-14 11:59:45 -07:00
) ,
2022-11-14 15:36:34 -07:00
) ,
Gap ( $styles . insets . lg ) ,
2022-11-14 14:27:17 -07:00
2023-04-18 11:03:17 -06:00
/// TimelineBtn
2023-01-04 22:13:26 -07:00
_TimelineBtn ( type: _data . type , width: $styles . sizes . maxContentWidth2 ) ,
2022-12-23 09:19:41 -07:00
Gap ( $styles . insets . lg ) ,
2022-11-14 15:36:34 -07:00
] ,
) ,
] ,
2022-11-14 11:59:45 -07:00
) ,
2022-08-29 20:38:28 -06:00
) ;
} ) ;
}
}