Skip to content

Commit

Permalink
Migration to Flutter 3.16
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k committed Jan 4, 2024
1 parent 72ac084 commit 9ca6b92
Show file tree
Hide file tree
Showing 23 changed files with 237 additions and 190 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

- Make sure you have installed flutter and all the requirements
- [Official flutter installation guide](https://docs.flutter.dev/get-started/install)
- Currently, the app uses the latest stable version of Flutter (3.13).
- Currently, the app uses the latest stable version of Flutter (3.16).


We have predefined run configurations for Android Studio and Visual Studio Code
Expand Down
2 changes: 1 addition & 1 deletion flutter-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.13.6
3.16.5
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class SmoothModalSheetHeaderButton extends StatelessWidget

@override
double widgetHeight(BuildContext context) {
return math.max(17.0 * MediaQuery.textScaleFactorOf(context),
return math.max(MediaQuery.textScalerOf(context).scale(17.0),
suffix is Icon || prefix is Icon ? 20.0 : 0.0) +
_padding.vertical;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/smooth_app/lib/helpers/extension_on_text_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extension Selectable on Text {
style: style,
strutStyle: strutStyle,
textDirection: textDirection,
textScaleFactor: textScaleFactor,
textScaler: textScaler,
textAlign: textAlign,
maxLines: maxLines,
// TODO(m123): Fix or remove alltogether
Expand All @@ -23,7 +23,7 @@ extension Selectable on Text {
style: style,
strutStyle: strutStyle,
textDirection: textDirection,
textScaleFactor: textScaleFactor,
textScaler: textScaler,
textAlign: textAlign,
maxLines: maxLines,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/pages/all_product_list_modal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AllProductListModal extends StatelessWidget {
ConstrainedBox(
constraints: BoxConstraints(
minWidth: double.infinity,
minHeight: 80.0 * MediaQuery.of(context).textScaleFactor,
minHeight: MediaQuery.textScalerOf(context).scale(80.0),
),
child: FutureBuilder<void>(
future: daoProductList.get(productList),
Expand Down
5 changes: 3 additions & 2 deletions packages/smooth_app/lib/pages/crop_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import 'package:smooth_app/pages/product/edit_image_button.dart';
import 'package:smooth_app/pages/product/may_exit_page_helper.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';
import 'package:smooth_app/widgets/will_pop_scope.dart';

/// Page dedicated to image cropping. Pops the resulting file path if relevant.
class CropPage extends StatefulWidget {
Expand Down Expand Up @@ -151,8 +152,8 @@ class _CropPageState extends State<CropPage> {
Widget build(final BuildContext context) {
_screenSize = MediaQuery.of(context).size;
final AppLocalizations appLocalizations = AppLocalizations.of(context);
return WillPopScope(
onWillPop: () async => _mayExitPage(saving: false),
return WillPopScope2(
onWillPop: () async => (await _mayExitPage(saving: false), null),
child: SmoothScaffold(
appBar: SmoothAppBar(
centerTitle: false,
Expand Down
5 changes: 3 additions & 2 deletions packages/smooth_app/lib/pages/hunger_games/question_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:smooth_app/pages/hunger_games/question_card.dart';
import 'package:smooth_app/query/product_questions_query.dart';
import 'package:smooth_app/query/questions_query.dart';
import 'package:smooth_app/query/random_questions_query.dart';
import 'package:smooth_app/widgets/will_pop_scope.dart';

Future<void> openQuestionPage(
BuildContext context, {
Expand Down Expand Up @@ -203,13 +204,13 @@ class _QuestionPageState extends State<_QuestionPage>

@override
Widget build(BuildContext context) {
return WillPopScope(
return WillPopScope2(
onWillPop: () async {
final Function()? callback = widget.updateProductUponAnswers;
if (_lastAnswer != null && callback != null) {
await callback();
}
return true;
return (true, null);
},
child: Center(
child: AnimatedSwitcher(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:smooth_app/pages/onboarding/scan_example.dart';
import 'package:smooth_app/pages/onboarding/welcome_page.dart';
import 'package:smooth_app/pages/page_manager.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';
import 'package:smooth_app/widgets/will_pop_scope.dart';

enum OnboardingPage {
NOT_STARTED,
Expand Down Expand Up @@ -121,8 +122,8 @@ enum OnboardingPage {
BuildContext context,
Widget widget,
) =>
WillPopScope(
onWillPop: () async => false,
WillPopScope2(
onWillPop: () async => (false, null),
// wrap the widget in [Builder] to allow navigation on the [context].
child: Builder(
builder: (BuildContext context) => SmoothScaffold(
Expand Down
7 changes: 4 additions & 3 deletions packages/smooth_app/lib/pages/page_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:smooth_app/data_models/preferences/user_preferences.dart';
import 'package:smooth_app/pages/carousel_manager.dart';
import 'package:smooth_app/pages/preferences/user_preferences_dev_mode.dart';
import 'package:smooth_app/widgets/tab_navigator.dart';
import 'package:smooth_app/widgets/will_pop_scope.dart';

enum BottomNavigationTab {
Profile,
Expand Down Expand Up @@ -103,18 +104,18 @@ class PageManagerState extends State<PageManager> {
),
],
);
return WillPopScope(
return WillPopScope2(
onWillPop: () async {
final bool isFirstRouteInCurrentTab =
!await _navigatorKeys[_currentPage]!.currentState!.maybePop();
if (isFirstRouteInCurrentTab) {
if (_currentPage != BottomNavigationTab.Scan) {
_selectTab(BottomNavigationTab.Scan, 1);
return false;
return (false, null);
}
}
// let system handle back button if we're on the first route
return isFirstRouteInCurrentTab;
return (isFirstRouteInCurrentTab, null);
},
child: Scaffold(
body: Stack(children: tabs),
Expand Down
171 changes: 86 additions & 85 deletions packages/smooth_app/lib/pages/product/add_basic_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:smooth_app/pages/product/multilingual_helper.dart';
import 'package:smooth_app/pages/text_field_helper.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';
import 'package:smooth_app/widgets/will_pop_scope.dart';

/// Input of a product's basic details, like name, quantity and brands.
///
Expand Down Expand Up @@ -86,105 +87,105 @@ class _AddBasicDetailsPageState extends State<AddBasicDetailsPage> {
Widget build(BuildContext context) {
final Size size = MediaQuery.sizeOf(context);
final AppLocalizations appLocalizations = AppLocalizations.of(context);
return WillPopScope(
onWillPop: () async => _mayExitPage(saving: false),
return WillPopScope2(
onWillPop: () async => (await _mayExitPage(saving: false), null),
child: UnfocusWhenTapOutside(
child: SmoothScaffold(
fixKeyboard: true,
appBar: SmoothAppBar(
centerTitle: false,
title: Text(appLocalizations.basic_details),
subTitle: buildProductTitle(widget.product, appLocalizations),
),
body: Form(
key: _formKey,
child: Scrollbar(
child: ListView(
children: <Widget>[
Align(
alignment: AlignmentDirectional.topStart,
child: ProductImageCarousel(
_product,
height: size.height * 0.20,
),
),
SizedBox(height: _heightSpace),
Padding(
padding: EdgeInsets.symmetric(
horizontal: size.width * 0.05,
centerTitle: false,
title: Text(appLocalizations.basic_details),
subTitle: buildProductTitle(widget.product, appLocalizations),
),
body: Form(
key: _formKey,
child: Scrollbar(
child: ListView(
children: <Widget>[
Align(
alignment: AlignmentDirectional.topStart,
child: ProductImageCarousel(
_product,
height: size.height * 0.20,
),
),
child: Column(
children: <Widget>[
Text(
appLocalizations.barcode_barcode(_product.barcode!),
style:
Theme.of(context).textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
SizedBox(height: _heightSpace),
if (_multilingualHelper.isMonolingual())
SmoothTextFormField(
controller: _productNameController,
type: TextFieldTypes.PLAIN_TEXT,
hintText: appLocalizations.product_name,
)
else
Card(
child: Column(
children: <Widget>[
_multilingualHelper
.getLanguageSelector(setState),
Padding(
padding: const EdgeInsets.all(8.0),
child: SmoothTextFormField(
controller: _productNameController,
type: TextFieldTypes.PLAIN_TEXT,
hintText: appLocalizations.product_name,
SizedBox(height: _heightSpace),
Padding(
padding: EdgeInsets.symmetric(
horizontal: size.width * 0.05,
),
child: Column(
children: <Widget>[
Text(
appLocalizations.barcode_barcode(_product.barcode!),
style:
Theme.of(context).textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
SizedBox(height: _heightSpace),
if (_multilingualHelper.isMonolingual())
SmoothTextFormField(
controller: _productNameController,
type: TextFieldTypes.PLAIN_TEXT,
hintText: appLocalizations.product_name,
)
else
Card(
child: Column(
children: <Widget>[
_multilingualHelper
.getLanguageSelector(setState),
Padding(
padding: const EdgeInsets.all(8.0),
child: SmoothTextFormField(
controller: _productNameController,
type: TextFieldTypes.PLAIN_TEXT,
hintText: appLocalizations.product_name,
),
),
),
],
],
),
),
SizedBox(height: _heightSpace),
LayoutBuilder(
builder: (
final BuildContext context,
final BoxConstraints constraints,
) =>
SmoothAutocompleteTextField(
focusNode: _focusNode,
controller: _brandNameController,
autocompleteKey: _autocompleteKey,
hintText: appLocalizations.brand_name,
constraints: constraints,
manager: AgnosticSuggestionManager.brand(),
),
),
SizedBox(height: _heightSpace),
LayoutBuilder(
builder: (
final BuildContext context,
final BoxConstraints constraints,
) =>
SmoothAutocompleteTextField(
focusNode: _focusNode,
controller: _brandNameController,
autocompleteKey: _autocompleteKey,
hintText: appLocalizations.brand_name,
constraints: constraints,
manager: AgnosticSuggestionManager.brand(),
SizedBox(height: _heightSpace),
SmoothTextFormField(
controller: _weightController,
type: TextFieldTypes.PLAIN_TEXT,
hintText: appLocalizations.quantity,
),
),
SizedBox(height: _heightSpace),
SmoothTextFormField(
controller: _weightController,
type: TextFieldTypes.PLAIN_TEXT,
hintText: appLocalizations.quantity,
),
// in order to be able to scroll suggestions
SizedBox(height: MediaQuery.sizeOf(context).height),
],
// in order to be able to scroll suggestions
SizedBox(height: MediaQuery.sizeOf(context).height),
],
),
),
),
],
],
),
),
),
),
bottomNavigationBar: ProductBottomButtonsBar(
onSave: () async => _exitPage(
await _mayExitPage(saving: true),
),
onCancel: () async => _exitPage(
await _mayExitPage(saving: false),
bottomNavigationBar: ProductBottomButtonsBar(
onSave: () async => _exitPage(
await _mayExitPage(saving: true),
),
onCancel: () async => _exitPage(
await _mayExitPage(saving: false),
),
),
),
),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import 'package:smooth_app/pages/product/product_image_swipeable_view.dart';
import 'package:smooth_app/pages/product/simple_input_page_helpers.dart';
import 'package:smooth_app/query/product_query.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';
import 'package:smooth_app/widgets/will_pop_scope.dart';

/// "Create a product we couldn't find on the server" page.
class AddNewProductPage extends StatefulWidget {
Expand Down Expand Up @@ -218,8 +219,8 @@ class _AddNewProductPageState extends State<AddNewProductPage>
tracker.track();
}

return WillPopScope(
onWillPop: _onWillPop,
return WillPopScope2(
onWillPop: () async => (await _onWillPop(), null),
child: SmoothScaffold(
body: SafeArea(
child: Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:smooth_app/pages/product/may_exit_page_helper.dart';
import 'package:smooth_app/pages/text_field_helper.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';
import 'package:smooth_app/widgets/will_pop_scope.dart';

/// Input of a product's less significant details, like website.
class AddOtherDetailsPage extends StatefulWidget {
Expand Down Expand Up @@ -54,8 +55,8 @@ class _AddOtherDetailsPageState extends State<AddOtherDetailsPage> {
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
final AppLocalizations appLocalizations = AppLocalizations.of(context);
return WillPopScope(
onWillPop: () async => _mayExitPage(saving: false),
return WillPopScope2(
onWillPop: () async => (await _mayExitPage(saving: false), null),
child: SmoothScaffold(
fixKeyboard: true,
appBar: SmoothAppBar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import 'package:smooth_app/pages/product_list_user_dialog_helper.dart';
import 'package:smooth_app/query/product_query.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';
import 'package:smooth_app/widgets/will_pop_scope.dart';

/// Displays the products of a product list, with access to other lists.
class ProductListPage extends StatefulWidget {
Expand Down Expand Up @@ -274,8 +275,8 @@ class _ProductListPageState extends State<ProductListPage>
),
),
)
: WillPopScope(
onWillPop: _handleUserBacktap,
: WillPopScope2(
onWillPop: () async => (await _handleUserBacktap(), null),
child: RefreshIndicator(
//if it is in selectmode then refresh indicator is not shown
notificationPredicate:
Expand Down
Loading

0 comments on commit 9ca6b92

Please sign in to comment.