|
| 1 | +import 'package:df_screen/df_screen.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | + |
| 4 | +void main() { |
| 5 | + runApp(const MyApp()); |
| 6 | +} |
| 7 | + |
| 8 | +class MyApp extends StatelessWidget { |
| 9 | + const MyApp({super.key}); |
| 10 | + |
| 11 | + @override |
| 12 | + Widget build(BuildContext context) { |
| 13 | + return const MaterialApp( |
| 14 | + debugShowCheckedModeBanner: false, |
| 15 | + title: 'Adaptive Screen Example', |
| 16 | + home: ExampleScreen(), |
| 17 | + ); |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +base class ExampleScreen extends Screen { |
| 22 | + const ExampleScreen({super.key}); |
| 23 | + |
| 24 | + @override |
| 25 | + State createState() => ExampleScreenState(); |
| 26 | + |
| 27 | + @override |
| 28 | + ScreenController createController(Screen screen, ScreenState state) { |
| 29 | + return ExampleScreenController(screen, state); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +final class ExampleScreenController extends ScreenController { |
| 34 | + ExampleScreenController(super.screen, super.state); |
| 35 | +} |
| 36 | + |
| 37 | +final class ExampleScreenState |
| 38 | + extends AdaptiveScreenState<ExampleScreen, ExampleScreenController> { |
| 39 | + @override |
| 40 | + AdaptiveScreenSideMode get topSideMode => AdaptiveScreenSideMode.SLIVER; |
| 41 | + |
| 42 | + @override |
| 43 | + AdaptiveScreenSideMode get leftSideMode => |
| 44 | + AdaptiveScreenSideMode.OVERLAY_WITH_PADDING; |
| 45 | + |
| 46 | + @override |
| 47 | + AdaptiveScreenSideMode get rightSideMode => AdaptiveScreenSideMode.OVERLAY; |
| 48 | + |
| 49 | + @override |
| 50 | + AdaptiveScreenSideMode get bottomSideMode => AdaptiveScreenSideMode.STATIC; |
| 51 | + |
| 52 | + @override |
| 53 | + double get minTopSideSize => 80.0; |
| 54 | + |
| 55 | + @override |
| 56 | + Widget topSide(BuildContext context, double topInsets) { |
| 57 | + return AdaptiveScrollBuilder( |
| 58 | + controller: bodyScrollController, |
| 59 | + expandedSize: 250.0, |
| 60 | + collapsedSize: minTopSideSize, |
| 61 | + child: Container( |
| 62 | + decoration: BoxDecoration( |
| 63 | + gradient: LinearGradient( |
| 64 | + colors: [Colors.teal.shade800, Colors.teal.shade400], |
| 65 | + begin: Alignment.topLeft, |
| 66 | + end: Alignment.bottomRight, |
| 67 | + ), |
| 68 | + boxShadow: const [ |
| 69 | + BoxShadow(color: Colors.black26, blurRadius: 10.0), |
| 70 | + ], |
| 71 | + ), |
| 72 | + child: const Center( |
| 73 | + child: Opacity( |
| 74 | + opacity: 0.3, |
| 75 | + child: Icon(Icons.waves, size: 300.0, color: Colors.white), |
| 76 | + ), |
| 77 | + ), |
| 78 | + ), |
| 79 | + builder: (context, percentage, staticChild) { |
| 80 | + return SizedBox( |
| 81 | + height: 250.0, |
| 82 | + child: Stack( |
| 83 | + children: [ |
| 84 | + Positioned.fill(child: staticChild!), |
| 85 | + Positioned( |
| 86 | + bottom: 20.0 + (20.0 * (1.0 - percentage)), |
| 87 | + left: 20.0, |
| 88 | + child: Opacity( |
| 89 | + opacity: percentage, |
| 90 | + child: const Text( |
| 91 | + 'Large Expanded Title', |
| 92 | + style: TextStyle( |
| 93 | + color: Colors.white, |
| 94 | + fontSize: 32.0, |
| 95 | + fontWeight: FontWeight.bold, |
| 96 | + ), |
| 97 | + ), |
| 98 | + ), |
| 99 | + ), |
| 100 | + Positioned( |
| 101 | + top: 40.0, |
| 102 | + left: 0.0, |
| 103 | + right: 0.0, |
| 104 | + child: Opacity( |
| 105 | + opacity: (1.0 - percentage), |
| 106 | + child: const Center( |
| 107 | + child: Text( |
| 108 | + 'My App', |
| 109 | + style: TextStyle( |
| 110 | + color: Colors.white, |
| 111 | + fontWeight: FontWeight.bold, |
| 112 | + fontSize: 20.0, |
| 113 | + ), |
| 114 | + ), |
| 115 | + ), |
| 116 | + ), |
| 117 | + ), |
| 118 | + ], |
| 119 | + ), |
| 120 | + ); |
| 121 | + }, |
| 122 | + ); |
| 123 | + } |
| 124 | + |
| 125 | + @override |
| 126 | + Widget leftSide(BuildContext context, double leftInsets) { |
| 127 | + return AdaptiveScrollBuilder( |
| 128 | + controller: bodyScrollController, |
| 129 | + expandedSize: 300.0, |
| 130 | + collapsedSize: 0.0, |
| 131 | + builder: (context, percentage, _) { |
| 132 | + return Container( |
| 133 | + width: 70.0, |
| 134 | + decoration: BoxDecoration( |
| 135 | + color: Color.lerp( |
| 136 | + Colors.white.withAlpha(200), |
| 137 | + Colors.teal.shade50.withAlpha(240), |
| 138 | + 1.0 - percentage, |
| 139 | + ), |
| 140 | + border: Border(right: BorderSide(color: Colors.grey.shade300)), |
| 141 | + ), |
| 142 | + child: Column( |
| 143 | + mainAxisAlignment: MainAxisAlignment.center, |
| 144 | + children: [ |
| 145 | + Transform.scale( |
| 146 | + scale: 0.8 + (0.4 * percentage), |
| 147 | + child: const Icon(Icons.dashboard, color: Colors.teal), |
| 148 | + ), |
| 149 | + const SizedBox(height: 20.0), |
| 150 | + const Icon(Icons.person, color: Colors.grey), |
| 151 | + const SizedBox(height: 20.0), |
| 152 | + Opacity( |
| 153 | + opacity: percentage, |
| 154 | + child: const Icon(Icons.settings, color: Colors.grey), |
| 155 | + ), |
| 156 | + ], |
| 157 | + ), |
| 158 | + ); |
| 159 | + }, |
| 160 | + ); |
| 161 | + } |
| 162 | + |
| 163 | + @override |
| 164 | + Widget rightSide(BuildContext context, double rightInsets) { |
| 165 | + return Align( |
| 166 | + alignment: Alignment.centerRight, |
| 167 | + child: Container( |
| 168 | + margin: const EdgeInsets.only(right: 10.0), |
| 169 | + padding: const EdgeInsets.symmetric(vertical: 20.0, horizontal: 8.0), |
| 170 | + decoration: BoxDecoration( |
| 171 | + color: Colors.black87, |
| 172 | + borderRadius: BorderRadius.circular(20.0), |
| 173 | + ), |
| 174 | + child: const Icon(Icons.arrow_upward, color: Colors.white), |
| 175 | + ), |
| 176 | + ); |
| 177 | + } |
| 178 | + |
| 179 | + @override |
| 180 | + Widget bottomSide(BuildContext context, double bottomInsets) { |
| 181 | + return Container( |
| 182 | + height: 60.0 + bottomInsets, |
| 183 | + color: Colors.white, |
| 184 | + padding: EdgeInsets.only(bottom: bottomInsets), |
| 185 | + child: const Center(child: Text('Static Bottom Footer')), |
| 186 | + ); |
| 187 | + } |
| 188 | + |
| 189 | + @override |
| 190 | + Widget body(BuildContext context) { |
| 191 | + return ListView.builder( |
| 192 | + controller: bodyScrollController, |
| 193 | + padding: EdgeInsets.only(top: topSideSize, bottom: 20.0), |
| 194 | + itemCount: 40, |
| 195 | + itemBuilder: (context, index) { |
| 196 | + return Card( |
| 197 | + margin: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0), |
| 198 | + elevation: 2.0, |
| 199 | + child: ListTile( |
| 200 | + title: Text('Item #$index'), |
| 201 | + subtitle: const Text('Scroll me!'), |
| 202 | + leading: CircleAvatar(child: Text('$index')), |
| 203 | + ), |
| 204 | + ); |
| 205 | + }, |
| 206 | + ); |
| 207 | + } |
| 208 | + |
| 209 | + @override |
| 210 | + Widget align(BuildContext context, Widget body, EdgeInsets sideInsets) { |
| 211 | + return Padding(padding: sideInsets, child: body); |
| 212 | + } |
| 213 | + |
| 214 | + @override |
| 215 | + EdgeInsets sideInsets(EdgeInsets preferredInsets) => preferredInsets; |
| 216 | +} |
0 commit comments