wonders/lib/ui/screens/wonder_details/wonders_details_screen.dart

76 lines
2.8 KiB
Dart
Raw Normal View History

2022-08-29 20:38:28 -06:00
import 'package:wonders/common_libs.dart';
import 'package:wonders/ui/common/lazy_indexed_stack.dart';
import 'package:wonders/ui/common/measurable_widget.dart';
import 'package:wonders/ui/screens/artifact/artifact_carousel/artifact_carousel_screen.dart';
import 'package:wonders/ui/screens/editorial/editorial_screen.dart';
import 'package:wonders/ui/screens/photo_gallery/photo_gallery.dart';
import 'package:wonders/ui/screens/wonder_details/wonder_details_tab_menu.dart';
import 'package:wonders/ui/screens/wonder_events/wonder_events.dart';
class WonderDetailsScreen extends StatefulWidget with GetItStatefulWidgetMixin {
WonderDetailsScreen({Key? key, required this.type, this.initialTabIndex = 0}) : super(key: key);
2022-08-29 20:38:28 -06:00
final WonderType type;
final int initialTabIndex;
2022-08-29 20:38:28 -06:00
@override
State<WonderDetailsScreen> createState() => _WonderDetailsScreenState();
}
2022-12-07 10:14:14 -07:00
class _WonderDetailsScreenState extends State<WonderDetailsScreen> with GetItStateMixin, StatefulPropsMixin {
late final _tabs = TabControllerProp(
this,
length: 4,
initialIndex: widget.initialTabIndex,
2022-12-07 10:14:14 -07:00
autoBuild: true,
);
2022-08-29 20:38:28 -06:00
final _detailsHasScrolled = ValueNotifier(false);
double? _tabBarHeight;
void _handleDetailsScrolled(double scrollPos) => _detailsHasScrolled.value = scrollPos > 0;
void _handleTabMenuSized(Size size) {
setState(() => _tabBarHeight = size.height - WonderDetailsTabMenu.buttonInset);
}
@override
Widget build(BuildContext context) {
final wonder = wondersLogic.getData(widget.type);
2022-12-07 10:14:14 -07:00
int tabIndex = _tabs.controller.index;
2022-08-29 20:38:28 -06:00
bool showTabBarBg = tabIndex != 1;
final tabBarHeight = _tabBarHeight ?? 0;
return ColoredBox(
color: Colors.black,
child: Stack(
children: [
/// Fullscreen tab views
LazyIndexedStack(
2022-12-07 10:14:14 -07:00
index: _tabs.controller.index,
2022-08-29 20:38:28 -06:00
children: [
WonderEditorialScreen(wonder, onScroll: _handleDetailsScrolled),
PhotoGallery(collectionId: wonder.unsplashCollectionId, wonderType: wonder.type),
Padding(padding: EdgeInsets.only(bottom: tabBarHeight), child: ArtifactCarouselScreen(type: wonder.type)),
Padding(padding: EdgeInsets.only(bottom: tabBarHeight), child: WonderEvents(type: widget.type)),
],
),
/// Tab menu
BottomCenter(
child: ValueListenableBuilder<bool>(
valueListenable: _detailsHasScrolled,
builder: (_, value, ___) => MeasurableWidget(
onChange: _handleTabMenuSized,
child: WonderDetailsTabMenu(
2022-12-07 10:14:14 -07:00
tabController: _tabs.controller,
2022-08-29 20:38:28 -06:00
wonderType: wonder.type,
showBg: showTabBarBg,
),
),
),
),
],
),
);
}
}