buildPresenter method
Build the page content.
Implementation
@override
Widget buildPresenter(BuildContext context) {
_safeAreaTop = MediaQuery.viewPaddingOf(context).top;
return Scaffold(
backgroundColor: const Color(0x00000000),
resizeToAvoidBottomInset: false,
body: Stack(
children: [
const Positioned.fill(
child: MediaFlightChrome(
child: ColoredBox(color: Color(0xFF000000)),
),
),
Positioned.fill(
child: ListenableBuilder(
listenable: Listenable.merge([_topBarHeight, _bottomStripHeight]),
builder: (ctx, _) => LayoutBuilder(
builder: (ctx2, constraints) {
_lastBody = constraints.biggest;
WidgetsBinding.instance.addPostFrameCallback((_) {
_publish();
});
return ListenableBuilder(
listenable: dragOffset,
builder: (ctx3, _) {
final viewport = MediaQuery.sizeOf(ctx3).height;
final dismissDistance = viewport / 4;
final progress = dismissDistance == 0
? 0.0
: (dragOffset.value.abs() / dismissDistance).clamp(
0.0,
1.0,
);
final scale = 1 - 0.1 * progress;
return Transform.scale(
scale: scale,
alignment: Alignment.topCenter,
child: Listener(
behavior: HitTestBehavior.translucent,
onPointerDown: _maybeDismissKeyboard,
child: ValueListenableBuilder<int>(
valueListenable: currentIndex,
builder: (ctx4, _, _) => DismissCarrier(
blocked: focusedEntry.isZoomed,
dragOffset: dragOffset,
onDismissCommitted: handleCancel,
child: PageView.builder(
controller: pageController,
itemCount: entries.length,
onPageChanged: _onPageChanged,
physics: entries.length > 1
? null
: NeverScrollableScrollPhysics(),
itemBuilder: (ctx5, i) => ComposeEntryView(
entry: entries[i],
flightEnabled: i == currentIndex.value,
),
),
),
),
),
);
},
);
},
),
),
),
// Floating top bar over the editor.
Positioned(
top: 0,
left: 0,
right: 0,
child: MediaFlightChrome(
child: OnSize(
onSize: (s) {
_topBarMeasured = true;
_topBarHeight.value = s.height;
},
child: SafeArea(
bottom: false,
child: Padding(
padding: EdgeInsets.only(left: 8, top: 4, bottom: 4),
child: Row(
children: [
Touch(
onPress: handleCancel,
child: Container(
width: 44,
height: 44,
alignment: Alignment.center,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: colors.onMedia.withValues(alpha: 0.15),
),
child: Icon(
CupertinoIcons.xmark,
color: colors.onMedia,
size: 18,
),
),
),
],
),
),
),
),
),
),
// Floating bottom strip (dot indicator + command bar +
// composer) inside KeyboardInsets so it tracks the soft
// keyboard.
Positioned(
bottom: 0,
left: 0,
right: 0,
child: MediaFlightChrome(
child: OnSize(
onSize: (s) {
_bottomStripMeasured = true;
_bottomStripHeight.value = s.height;
},
child: MediaHost.current.keyboardInsets(
builder: (context, bottom) => Container(
// Pad the bottom safe area / keyboard area INSIDE
// the colored container so its background covers the
// gap. Otherwise an InteractiveViewer-zoomed image
// beneath shows through the bottom safe-area strip.
color: const Color(0xCC000000),
padding: EdgeInsets.only(bottom: bottom),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (entries.length > 1)
ValueListenableBuilder<int>(
valueListenable: currentIndex,
builder: (context, i, _) =>
_DotIndicator(count: entries.length, active: i),
),
ValueListenableBuilder<int>(
valueListenable: currentIndex,
builder: (context, _, _) {
final e = focusedEntry;
if (e.input is! VideoMedia) {
return SizedBox.shrink();
}
// Telegram places the trim scrubber directly
// above the caption bar; it mounts once the
// preview controller knows the duration.
return ListenableBuilder(
listenable: e,
builder: (context, _) {
final ctrl = e.videoController;
if (ctrl == null || !ctrl.value.isInitialized) {
return SizedBox.shrink();
}
return VideoTrimScrubber(
entry: e,
duration: ctrl.value.duration,
);
},
);
},
),
if (_showsCaption)
ValueListenableBuilder<int>(
valueListenable: currentIndex,
builder: (context, _, _) =>
MediaHost.current.captionField(
bubbleKey: composerBubbleKey,
controller: focusedEntry.composerController,
focusNode: composerFocus,
onSubmit: handleSubmit,
placeholder: strings.addACaption,
),
),
ValueListenableBuilder<int>(
valueListenable: currentIndex,
builder: (context, _, _) {
final e = focusedEntry;
// Video tools edit poster-frame geometry.
final editable =
e.input is ImageMedia || e.input is VideoMedia;
return MediaCommandsBar(
onCrop: editable
? () => _openTool(e.openCropEditor)
: null,
onDraw: editable
? () => _openTool(e.openDrawEditor)
: null,
);
},
),
if (!_showsCaption)
Padding(
padding: EdgeInsets.fromLTRB(
space.lg,
0,
space.lg,
space.md,
),
child: SizedBox(
width: double.infinity,
child: MediaHost.current.confirmButton(
onPressed: handleSubmit,
),
),
),
],
),
),
),
),
),
),
],
),
);
}