Created
November 21, 2018 22:44
-
-
Save filiph/e46084361c3c9c270695c760aa06d30d to your computer and use it in GitHub Desktop.
Hot reload time out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| import 'package:flutter/rendering.dart'; | |
| import 'package:sliver_fbs/src/names.dart'; | |
| void main() => runApp(MyApp()); | |
| class MyApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| title: 'Flutter Demo', | |
| theme: ThemeData( | |
| primarySwatch: Colors.orange, | |
| ), | |
| home: MyHomePage(title: 'Flutter Demo Home Page'), | |
| ); | |
| } | |
| } | |
| class MyHomePage extends StatefulWidget { | |
| final String title; | |
| MyHomePage({Key key, this.title}) : super(key: key); | |
| @override | |
| _MyHomePageState createState() => _MyHomePageState(); | |
| } | |
| class _MyHomePageState extends State<MyHomePage> { | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| body: _buildScrollable(context), | |
| ); | |
| } | |
| Widget _buildScrollable(BuildContext context) { | |
| return CustomScrollView( | |
| slivers: [ | |
| SliverAppBar( | |
| title: Text('Hello'), | |
| expandedHeight: 200, | |
| flexibleSpace: Placeholder(), | |
| floating: true, | |
| // ========= TRY UNCOMMENTING THE FOLLOWING LINE AND HOT RELOADING ======== | |
| // pinned: true, | |
| ), | |
| SliverSomething( | |
| child: Container( | |
| color: Colors.orange, | |
| child: Text('hello'), | |
| height: 150, | |
| ), | |
| ), | |
| SliverPadding( | |
| padding: EdgeInsets.all(16), | |
| sliver: SliverList( | |
| delegate: SliverChildBuilderDelegate( | |
| (context, index) => _buildTile(context, allNames[index]), | |
| childCount: allNames.length, | |
| ), | |
| ), | |
| ) | |
| ], | |
| ); | |
| } | |
| Widget _buildTile(BuildContext context, Name name) { | |
| final style = Theme.of(context).textTheme.title; | |
| return Row( | |
| children: [ | |
| Padding( | |
| padding: EdgeInsets.all(16), | |
| child: Container( | |
| width: 16, | |
| height: 16, | |
| color: name.color, | |
| ), | |
| ), | |
| Text(name.camelCase, style: style), | |
| ], | |
| ); | |
| } | |
| } | |
| class SliverFilip extends SingleChildRenderObjectWidget { | |
| SliverFilip({Widget child, Key key}) : super(child: child, key: key); | |
| @override | |
| RenderObject createRenderObject(BuildContext context) { | |
| return RenderSliverFilip(); | |
| } | |
| } | |
| class SliverSomething extends SingleChildRenderObjectWidget { | |
| SliverSomething({Widget child, Key key}) : super(child: child, key: key); | |
| @override | |
| RenderObject createRenderObject(BuildContext context) { | |
| return RenderSliverFilip(); | |
| } | |
| } | |
| class RenderSliverFilip extends RenderSliverSingleBoxAdapter { | |
| RenderSliverFilip({ | |
| RenderBox child, | |
| }) : super(child: child); | |
| @override | |
| void performLayout() { | |
| if (child == null) { | |
| geometry = SliverGeometry.zero; | |
| return; | |
| } | |
| child.layout(constraints.asBoxConstraints(), parentUsesSize: true); | |
| double childExtent; | |
| switch (constraints.axis) { | |
| case Axis.horizontal: | |
| childExtent = child.size.width; | |
| break; | |
| case Axis.vertical: | |
| childExtent = child.size.height; | |
| break; | |
| } | |
| assert(childExtent != null); | |
| final isOdd = constraints.scrollOffset.toInt().isOdd; | |
| final extent = constraints.scrollOffset * 2; | |
| geometry = SliverGeometry( | |
| scrollExtent: isOdd ? 70 : 80, | |
| paintExtent: 70, | |
| paintOrigin: extent, | |
| maxPaintExtent: 70, | |
| ); | |
| setChildParentData(child, constraints, geometry); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment