|
| 1 | +import 'package:df_screen/df_screen.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | + |
| 4 | +void main() { |
| 5 | + runApp( |
| 6 | + const MaterialApp( |
| 7 | + debugShowCheckedModeBanner: false, |
| 8 | + home: Material(child: OverlayExampleScreen()), |
| 9 | + ), |
| 10 | + ); |
| 11 | +} |
| 12 | + |
| 13 | +/// 1. THE SCREEN |
| 14 | +base class OverlayExampleScreen extends Screen { |
| 15 | + const OverlayExampleScreen({super.key}); |
| 16 | + |
| 17 | + @override |
| 18 | + State createState() => _OverlayExampleScreenState(); |
| 19 | + |
| 20 | + @override |
| 21 | + ScreenController createController(Screen screen, ScreenState state) { |
| 22 | + return OverlayExampleController(screen, state); |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +/// 2. THE CONTROLLER (Business Logic) |
| 27 | +final class OverlayExampleController extends ScreenController { |
| 28 | + OverlayExampleController(super.screen, super.state); |
| 29 | + |
| 30 | + void onActionPressed() { |
| 31 | + print("Action button tapped!"); |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +/// 3. THE STATE (UI & Adaptive Layout) |
| 36 | +final class _OverlayExampleScreenState extends AdaptiveScreenState< |
| 37 | + OverlayExampleScreen, OverlayExampleController> { |
| 38 | + // Use OVERLAY so the body content scrolls behind the header/footer |
| 39 | + @override |
| 40 | + AdaptiveScreenSideMode get topSideMode => AdaptiveScreenSideMode.OVERLAY; |
| 41 | + |
| 42 | + @override |
| 43 | + AdaptiveScreenSideMode get bottomSideMode => AdaptiveScreenSideMode.OVERLAY; |
| 44 | + |
| 45 | + // By setting these, the framework avoids "layout jumps" on the first frame |
| 46 | + @override |
| 47 | + double get minTopSideSize => 80.0; |
| 48 | + @override |
| 49 | + double get minBottomSideSize => 90.0; |
| 50 | + |
| 51 | + /// THE HEADER (TopSide) |
| 52 | + @override |
| 53 | + Widget topSide(BuildContext context, double topInsets) { |
| 54 | + return PreferredSize( |
| 55 | + preferredSize: Size.fromHeight(minTopSideSize + topInsets), |
| 56 | + child: Container( |
| 57 | + margin: const EdgeInsets.all(12), |
| 58 | + decoration: BoxDecoration( |
| 59 | + // Glassmorphism effect |
| 60 | + color: Colors.white.withAlpha(200), |
| 61 | + borderRadius: BorderRadius.circular(16), |
| 62 | + boxShadow: [ |
| 63 | + BoxShadow( |
| 64 | + color: Colors.black.withAlpha(20), |
| 65 | + blurRadius: 10, |
| 66 | + offset: const Offset(0, 4), |
| 67 | + ) |
| 68 | + ], |
| 69 | + ), |
| 70 | + child: SafeArea( |
| 71 | + bottom: false, |
| 72 | + child: ListTile( |
| 73 | + leading: const CircleAvatar( |
| 74 | + backgroundColor: Colors.indigo, |
| 75 | + child: Icon(Icons.person, color: Colors.white)), |
| 76 | + title: const Text('Hello, Explorer', |
| 77 | + style: TextStyle(fontWeight: FontWeight.bold)), |
| 78 | + subtitle: const Text('Welcome back!'), |
| 79 | + trailing: IconButton( |
| 80 | + icon: const Icon(Icons.notifications_none), |
| 81 | + onPressed: c.onActionPressed, |
| 82 | + ), |
| 83 | + ), |
| 84 | + ), |
| 85 | + ), |
| 86 | + ); |
| 87 | + } |
| 88 | + |
| 89 | + /// THE NAVIGATION BAR (BottomSide) |
| 90 | + @override |
| 91 | + Widget bottomSide(BuildContext context, double bottomInsets) { |
| 92 | + return PreferredSize( |
| 93 | + preferredSize: Size.fromHeight(minBottomSideSize + bottomInsets), |
| 94 | + child: Container( |
| 95 | + padding: EdgeInsets.only( |
| 96 | + bottom: bottomInsets + 10, left: 20, right: 20, top: 10), |
| 97 | + child: Container( |
| 98 | + height: 60, |
| 99 | + decoration: BoxDecoration( |
| 100 | + color: Colors.indigo.shade900, |
| 101 | + borderRadius: BorderRadius.circular(30), |
| 102 | + boxShadow: const [BoxShadow(color: Colors.black45, blurRadius: 20)], |
| 103 | + ), |
| 104 | + child: Row( |
| 105 | + mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
| 106 | + children: [ |
| 107 | + _navIcon(Icons.home, true), |
| 108 | + _navIcon(Icons.search, false), |
| 109 | + _navIcon(Icons.favorite_border, false), |
| 110 | + _navIcon(Icons.settings, false), |
| 111 | + ], |
| 112 | + ), |
| 113 | + ), |
| 114 | + ), |
| 115 | + ); |
| 116 | + } |
| 117 | + |
| 118 | + Widget _navIcon(IconData icon, bool active) { |
| 119 | + return Icon(icon, color: active ? Colors.white : Colors.white54, size: 28); |
| 120 | + } |
| 121 | + |
| 122 | + /// THE MAIN CONTENT |
| 123 | + @override |
| 124 | + Widget body(BuildContext context) { |
| 125 | + return ListView.builder( |
| 126 | + // CRITICAL: Use the built-in controller for synchronized animations |
| 127 | + controller: bodyScrollController, |
| 128 | + // Add padding so the first/last items aren't hidden under the overlays |
| 129 | + padding: EdgeInsets.only( |
| 130 | + top: minTopSideSize + 30, |
| 131 | + bottom: minBottomSideSize + 20, |
| 132 | + left: 16, |
| 133 | + right: 16, |
| 134 | + ), |
| 135 | + itemCount: 25, |
| 136 | + itemBuilder: (context, index) { |
| 137 | + return Card( |
| 138 | + margin: const EdgeInsets.only(bottom: 12), |
| 139 | + shape: |
| 140 | + RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), |
| 141 | + child: Container( |
| 142 | + height: 100, |
| 143 | + padding: const EdgeInsets.all(16), |
| 144 | + child: Row( |
| 145 | + children: [ |
| 146 | + Container( |
| 147 | + width: 60, |
| 148 | + decoration: BoxDecoration( |
| 149 | + color: Colors.indigo.withAlpha(30), |
| 150 | + borderRadius: BorderRadius.circular(8), |
| 151 | + ), |
| 152 | + child: Center( |
| 153 | + child: Text('#$index', |
| 154 | + style: const TextStyle(fontWeight: FontWeight.bold))), |
| 155 | + ), |
| 156 | + const SizedBox(width: 16), |
| 157 | + const Expanded( |
| 158 | + child: Column( |
| 159 | + mainAxisAlignment: MainAxisAlignment.center, |
| 160 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 161 | + children: [ |
| 162 | + Text('Adaptive Overlay Card', |
| 163 | + style: TextStyle(fontWeight: FontWeight.bold)), |
| 164 | + Text('Scroll behind the floating bars...', |
| 165 | + style: TextStyle(color: Colors.grey)), |
| 166 | + ], |
| 167 | + ), |
| 168 | + ) |
| 169 | + ], |
| 170 | + ), |
| 171 | + ), |
| 172 | + ); |
| 173 | + }, |
| 174 | + ); |
| 175 | + } |
| 176 | + |
| 177 | + // Set the background color for the whole screen |
| 178 | + @override |
| 179 | + Widget background(BuildContext context) { |
| 180 | + return Container(color: Colors.grey.shade100); |
| 181 | + } |
| 182 | +} |
0 commit comments