import 'dart:math' as math; import 'package:flutter/material.dart'; const ink = Color(0xff36413c), blue = Color(0xff274956), muted = Color(0xff796b55), cream = Color(0xfff3e7cc), amber = Color(0xffe0b568); TextStyle hand(double size, {Color color = ink}) => TextStyle( fontFamily: 'MaraHand', fontSize: size, height: 1.30, color: color, ); Widget writing(String value, {double size = 23, Color color = ink}) => Padding( padding: const EdgeInsets.symmetric(vertical: 5), child: Text(value, style: hand(size, color: color)), ); class InkButton extends StatelessWidget { const InkButton( this.label, this.onPressed, { super.key, this.size = 23, this.primary = false, }); final String label; final VoidCallback? onPressed; final double size; final bool primary; @override Widget build(BuildContext context) => DecoratedBox( decoration: BoxDecoration( border: Border( bottom: BorderSide(color: blue.withValues(alpha: primary ? .5 : .18)), ), ), child: TextButton( onPressed: onPressed, style: TextButton.styleFrom( foregroundColor: blue, disabledForegroundColor: muted.withValues(alpha: .4), textStyle: hand(size), minimumSize: const Size(48, 48), padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 8), shape: const RoundedRectangleBorder(), ), child: Text(label, textAlign: TextAlign.center), ), ); } class Paper extends StatefulWidget { const Paper({super.key, required this.child, this.onTurn}); final Widget child; final ValueChanged? onTurn; @override State createState() => _PaperState(); } class _PaperState extends State { Offset? start; @override Widget build(BuildContext context) => ColoredBox( color: const Color(0xff314345), child: SafeArea( child: LayoutBuilder( builder: (context, c) { final landscape = c.maxWidth > c.maxHeight; final scale = landscape ? c.maxWidth / 1024 : math.min(c.maxWidth / 1024, c.maxHeight / 1536); final w = 1024 * scale, h = 1536 * scale, left = (c.maxWidth - w) / 2, top = (c.maxHeight - h) / 2; final narrow = c.maxWidth < 480; final content = landscape ? Rect.fromLTRB( c.maxWidth * .10, c.maxHeight * .06, c.maxWidth * .83, c.maxHeight * .94, ) : Rect.fromLTRB( left + w * (narrow ? .08 : .11), top + h * .12, left + w * (narrow ? .91 : .83), top + h * .91, ); return Listener( onPointerDown: (e) { start = (e.localPosition.dx < content.left || e.localPosition.dx > content.right) ? e.localPosition : null; }, onPointerUp: (e) { final origin = start; start = null; if (origin == null) return; final d = e.localPosition - origin; if (d.dx.abs() > 55 && d.dx.abs() > d.dy.abs() * 1.5) { widget.onTurn?.call(d.dx < 0 ? 1 : -1); } }, child: Stack( clipBehavior: Clip.hardEdge, children: [ Positioned( left: left, top: top, width: w, height: h, child: Image.asset( 'assets/artwork/mara-single-page-v2.png', fit: BoxFit.fill, excludeFromSemantics: true, ), ), Positioned.fromRect(rect: content, child: widget.child), ], ), ); }, ), ), ); } class Leaf extends StatelessWidget { const Leaf({super.key, required this.body, this.footer, this.onTurn}); final Widget body; final Widget? footer; final ValueChanged? onTurn; @override Widget build(BuildContext context) => Paper( onTurn: onTurn, child: Column( children: [ Expanded( child: SingleChildScrollView( key: const PageStorageKey('leaf-scroll'), padding: const EdgeInsets.fromLTRB(4, 0, 4, 8), child: body, ), ), ?footer, ], ), ); } class Cover extends StatelessWidget { const Cover({super.key, required this.onTap}); final VoidCallback onTap; @override Widget build(BuildContext context) => Semantics( button: true, label: 'Open Mara’s cloth-bound island notebook', child: GestureDetector( onTap: onTap, child: SizedBox( height: 230, child: Center( child: AspectRatio( aspectRatio: 1.5, child: LayoutBuilder( builder: (context, c) => Stack( children: [ Positioned.fill( child: Image.asset( 'assets/artwork/home-notebook-cover-v2.png', fit: BoxFit.fill, excludeFromSemantics: true, ), ), Positioned( left: c.maxWidth * .27, top: c.maxHeight * .32, width: c.maxWidth * .49, height: c.maxHeight * .34, child: Center( child: Transform.rotate( angle: -.044, child: Text( 'Mara’s\nisland notebook', textAlign: TextAlign.center, style: hand(28), ), ), ), ), ], ), ), ), ), ), ), ); } class Sketch extends StatelessWidget { const Sketch(this.kind, {super.key, this.height = 140}); final String kind; final double height; @override Widget build(BuildContext context) => Semantics( image: true, label: kind == 'match' ? 'A pencil sketch of a match and a small amber flame' : 'A folded note sealed with red wax', child: SizedBox( height: height, width: double.infinity, child: CustomPaint(painter: _SketchPainter(kind)), ), ); } class _SketchPainter extends CustomPainter { _SketchPainter(this.kind); final String kind; @override void paint(Canvas c, Size s) { final p = Paint()..isAntiAlias = true; final x = s.width * .51, h = s.height; if (kind == 'match') { p ..color = const Color(0xff997445) ..strokeWidth = h * .045; c.drawLine(Offset(x - 25, h * .88), Offset(x + 12, h * .36), p); p.color = const Color(0xff654539); c.drawOval(Rect.fromLTRB(x + 2, h * .27, x + 26, h * .41), p); p.color = amber; final f = Path() ..moveTo(x + 12, h * .33) ..cubicTo(x - 24, h * .17, x + 30, h * .19, x + 17, h * .05) ..cubicTo(x + 56, h * .20, x + 32, h * .33, x + 12, h * .33); c.drawPath(f, p); } else { final r = Rect.fromLTRB(s.width * .10, h * .15, s.width * .90, h * .86); p.color = const Color(0xffead9b2); c.drawRect(r, p); p ..color = const Color(0xffb8a17c) ..style = PaintingStyle.stroke ..strokeWidth = 1.5; c.drawRect(r, p); c.drawPath( Path() ..moveTo(r.left, r.top) ..lineTo(s.width * .5, h * .59) ..lineTo(r.right, r.top), p, ); c.drawLine(r.bottomLeft, Offset(s.width * .4, h * .5), p); c.drawLine(r.bottomRight, Offset(s.width * .6, h * .5), p); p ..style = PaintingStyle.fill ..color = const Color(0xff9e5f49); c.drawCircle(Offset(s.width * .5, h * .57), h * .075, p); } } @override bool shouldRepaint(_SketchPainter old) => old.kind != kind; }