diff --git a/web_native/lib/screens/home_screen.dart b/web_native/lib/screens/home_screen.dart index 1db29ed..ba19fed 100644 --- a/web_native/lib/screens/home_screen.dart +++ b/web_native/lib/screens/home_screen.dart @@ -21,12 +21,8 @@ class _HomeScreenState extends State { HomeBloc bloc; - ScrollController _gridViewController = new ScrollController(); - ScrollController _parentController = new ScrollController(); - int _currentIndex = 0; int _totalLength = 1; - double _lastOffset = 0.0; @override Widget build(BuildContext context) { @@ -39,32 +35,12 @@ class _HomeScreenState extends State { } void _init(){ - _gridViewController.addListener(_scrollListener); - if(bloc != null) return; bloc = HomeBloc(AppProvider.getApplication(context)); } - // Needed Due to Nested Scroll Views - void _scrollListener() { - // Reflect Downwards & Upwards Scrolling (Respectively) on Parent - if (_gridViewController.offset > _lastOffset) { - if (_parentController.offset < _parentController.position.maxScrollExtent) { - _parentController.jumpTo(_parentController.offset + (_lastOffset - _gridViewController.offset).abs()); - } - } else if (_gridViewController.offset < _lastOffset) { - if (_parentController.offset > 0) { - _parentController.jumpTo(_parentController.offset - (_lastOffset - _gridViewController.offset).abs()); - } - } - - // Don't update offset on top or bottom bounce - if (_gridViewController.offset < _gridViewController.position.maxScrollExtent && _gridViewController.offset > 0) - _lastOffset = _gridViewController.offset; - } - @override void dispose() { super.dispose(); @@ -75,9 +51,7 @@ class _HomeScreenState extends State { var widgetMap = [ [ _buildAppBar("Gallery"), - SliverFillRemaining( - child: _buildGridView() - ) + _buildGridView() ], [ _buildAppBar("Albums"), @@ -90,7 +64,6 @@ class _HomeScreenState extends State { ]; return CustomScrollView( shrinkWrap: true, - controller: _parentController, slivers: widgetMap[_currentIndex], ); } @@ -158,23 +131,17 @@ class _HomeScreenState extends State { Widget _buildGridView() { MediaQueryData queryData = MediaQuery.of(context); - final int itemMultiplier = 3; - final int crossAxisCount = (queryData.size.width * itemMultiplier / 500).ceil(); - final int derivedContentWidth = 500; + // Can change this to change desired image size + final int desiredContentWidth = 500; - return new StaggeredGridView.builder( - shrinkWrap: true, + return SliverStaggeredGrid.extentBuilder( itemCount: _totalLength, - controller: _gridViewController, - gridDelegate: SliverStaggeredGridDelegateWithFixedCrossAxisCount( - staggeredTileCount: _totalLength, - crossAxisCount: crossAxisCount, - mainAxisSpacing: 4.0, - crossAxisSpacing: 4.0, - staggeredTileBuilder: (int index) => new StaggeredTile.fit(1), - ), + mainAxisSpacing: 4.0, + crossAxisSpacing: 4.0, + maxCrossAxisExtent: 500 / queryData.devicePixelRatio, + staggeredTileBuilder: (int index) => new StaggeredTile.fit(1), itemBuilder: (BuildContext context, int index) { - return _buildCard(index, derivedContentWidth); + return _buildCard(index, desiredContentWidth); }, ); } @@ -196,19 +163,6 @@ class _HomeScreenState extends State { }); return snapshot.data; - - // WidgetsBinding.instance.addPostFrameCallback((_) { - // if (_totalLength == bloc.cachedMediaItemList.length - 1) - // return; - - // if (bloc.cachedMediaItemList.length == 0) - // return; - - // setState(() { - // _totalLength = bloc.cachedMediaItemList.length - 1; - // }); - // }); - } ); }