Widget _buildFab() { //starting fab position finaldouble defaultTopMargin = 256.0 - 4.0; //pixels from top where scaling should start finaldouble scaleStart = 96.0; //pixels from top where scaling should end finaldouble scaleEnd = scaleStart / 2;
double top = defaultTopMargin; double scale = 1.0; if (_scrollController.hasClients) { double offset = _scrollController.offset; top -= offset; if (offset < defaultTopMargin - scaleStart) { //offset small => don't scale down scale = 1.0; } elseif (offset < defaultTopMargin - scaleEnd) { //offset between scaleStart and scaleEnd => scale down scale = (defaultTopMargin - scaleEnd - offset) / scaleEnd; } else { //offset passed scaleEnd => hide fab scale = 0.0; } }
returnnew Positioned( top: top, right: 16.0, child: new Transform( transform: new Matrix4.identity()..scale(scale), alignment: Alignment.center, child: new FloatingActionButton( onPressed: () => {}, child: new Icon(Icons.add), ), ), ); }