From 51d79fdbf232a4bedac53dc0fbd842d4eec20bff Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Thu, 9 Jul 2020 12:50:24 +0200 Subject: [PATCH] PurchaseScreen: Fix scrolling Putting a column inside a SingleChildScrollView is way way too complex. There are lots of different solutions, and not all seem to work for me. Also adjust the loading screen. --- lib/screens/purchase_screen.dart | 45 ++++++++++----------------- lib/widgets/purchase_widget.dart | 53 ++------------------------------ 2 files changed, 19 insertions(+), 79 deletions(-) diff --git a/lib/screens/purchase_screen.dart b/lib/screens/purchase_screen.dart index 98bb67fb..6f801f3a 100644 --- a/lib/screens/purchase_screen.dart +++ b/lib/screens/purchase_screen.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'dart:io'; -import 'dart:math'; import 'package:flutter/material.dart'; @@ -48,6 +47,7 @@ class PurchaseScreen extends StatelessWidget { var body = Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, children: [ Text( 'Support GitJournal by going Pro and additionally get -', @@ -77,10 +77,13 @@ class PurchaseScreen extends StatelessWidget { style: titleStyle, textAlign: TextAlign.center, ), + const SizedBox(height: 32.0), body, + const SizedBox(height: 32.0), PurchaseWidget(), ], - mainAxisAlignment: MainAxisAlignment.spaceAround, + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.min, ); if (Platform.isIOS) { @@ -99,10 +102,17 @@ class PurchaseScreen extends StatelessWidget { ); } - return _SingleChildScrollViewExpanded( - child: SafeArea(child: w), - padding: const EdgeInsets.all(16.0), - ); + w = Padding(padding: const EdgeInsets.all(16.0), child: w); + + return SafeArea( + child: CustomScrollView( + slivers: [ + SliverFillRemaining( + hasScrollBody: false, + child: w, + ), + ], + )); } Future _onWillPop() async { @@ -122,26 +132,3 @@ class EmptyAppBar extends StatelessWidget implements PreferredSizeWidget { @override Size get preferredSize => const Size(0.0, 0.0); } - -class _SingleChildScrollViewExpanded extends StatelessWidget { - final Widget child; - final EdgeInsetsGeometry padding; - - _SingleChildScrollViewExpanded({this.child, this.padding}); - - @override - Widget build(BuildContext context) { - return LayoutBuilder( - builder: (BuildContext context, BoxConstraints constraints) { - return SingleChildScrollView( - child: ConstrainedBox( - constraints: BoxConstraints.tightFor( - height: max(100, constraints.maxHeight)), - child: child, - ), - padding: padding, - ); - }, - ); - } -} diff --git a/lib/widgets/purchase_widget.dart b/lib/widgets/purchase_widget.dart index 8657c14a..c8f5ad71 100644 --- a/lib/widgets/purchase_widget.dart +++ b/lib/widgets/purchase_widget.dart @@ -77,55 +77,6 @@ class PurchaseButton extends StatelessWidget { } } -class LoadingWidget extends StatelessWidget { - const LoadingWidget({Key key}) : super(key: key); - - @override - Widget build(BuildContext context) { - var theme = Theme.of(context); - var children = [ - Padding( - padding: const EdgeInsets.all(8.0), - child: Text( - "Loading", - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.headline4, - ), - ), - const SizedBox(height: 8.0), - const Padding( - padding: EdgeInsets.all(8.0), - child: CircularProgressIndicator( - value: null, - ), - ), - ]; - - var w = Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: children, - ); - - return WillPopScope( - onWillPop: _onWillPopLoading, - child: Container( - child: w, - color: theme.scaffoldBackgroundColor, - padding: const EdgeInsets.all(16.0), - constraints: const BoxConstraints.expand(), - ), - ); - } - - Future _onWillPopLoading() async { - getAnalytics().logEvent( - name: "purchase_screen_close_loading", - ); - return true; - } -} - class PurchaseWidget extends StatefulWidget { @override _PurchaseWidgetState createState() => _PurchaseWidgetState(); @@ -207,7 +158,9 @@ class _PurchaseWidgetState extends State { @override Widget build(BuildContext context) { - return _offerings == null ? const LoadingWidget() : buildBody(context); + return _offerings == null + ? const CircularProgressIndicator() + : buildBody(context); } Widget buildBody(BuildContext context) {