Skip to content

Commit

Permalink
chore: Migration to Flutter 3.16 (#4917)
Browse files Browse the repository at this point in the history
* Migration to Flutter 3.16

* Dart format

---------

Co-authored-by: monsieurtanuki <[email protected]>
  • Loading branch information
g123k and monsieurtanuki authored Jan 9, 2024
1 parent 5c88a87 commit bccdf1c
Show file tree
Hide file tree
Showing 23 changed files with 156 additions and 107 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:smooth_app/pages/product/may_exit_page_helper.dart';
import 'package:smooth_app/pages/product/multilingual_helper.dart';
import 'package:smooth_app/pages/text_field_helper.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 @@ -85,8 +86,8 @@ 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,
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 @@ -10,6 +10,7 @@ import 'package:smooth_app/pages/product/common/product_buttons.dart';
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_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 @@ -53,8 +54,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: buildEditProductAppBar(
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
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class _ProductQueryPageState extends State<ProductQueryPage>
final List<Country> localizedCountries =
await IsoCountries.isoCountriesForLocale(locale);
for (final Country country in localizedCountries) {
if (country.countryCode.toLowerCase() == _country!.offTag.toLowerCase()) {
if (country.countryCode.toLowerCase() == _country.offTag.toLowerCase()) {
return country.name;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import 'package:smooth_app/pages/product/simple_input_number_field.dart';
import 'package:smooth_app/query/product_query.dart';
import 'package:smooth_app/themes/color_schemes.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';
import 'package:smooth_app/widgets/will_pop_scope.dart';

/// Edit display of a product packagings (the new api V3 version).
class EditNewPackagings extends StatefulWidget {
Expand Down Expand Up @@ -182,8 +183,8 @@ class _EditNewPackagingsState extends State<EditNewPackagings>
),
);

return WillPopScope(
onWillPop: () async => _mayExitPage(saving: false),
return WillPopScope2(
onWillPop: () async => (await _mayExitPage(saving: false), null),
child: UnfocusWhenTapOutside(
child: SmoothScaffold(
fixKeyboard: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class MultilingualHelper {
}

// Fallback: we may have old data where there are no translations.
controller.text = _initialMonolingualText!;
controller.text = _initialMonolingualText;
}

// TODO(monsieurtanuki): we would be better off always never monolingual
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import 'package:smooth_app/pages/product/ordered_nutrients_cache.dart';
import 'package:smooth_app/pages/product/simple_input_number_field.dart';
import 'package:smooth_app/pages/text_field_helper.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';
import 'package:smooth_app/widgets/will_pop_scope.dart';

/// Actual nutrition page, with data already loaded.
class NutritionPageLoaded extends StatefulWidget {
Expand Down Expand Up @@ -190,8 +191,8 @@ class _NutritionPageLoadedState extends State<NutritionPageLoaded>
_focusNodes.clear();
}

return WillPopScope(
onWillPop: () async => _mayExitPage(saving: false),
return WillPopScope2(
onWillPop: () async => (await _mayExitPage(saving: false), null),
child: SmoothScaffold(
fixKeyboard: true,
appBar: buildEditProductAppBar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class _PortionCalculatorState extends State<PortionCalculator> {
),
const SizedBox(height: MEDIUM_SPACE),
Container(
height: (data.textScaleFactor * (SMALL_SPACE * 2 + 15.0)) * 1.2,
height:
MediaQuery.textScalerOf(context).scale(SMALL_SPACE * 2 + 15.0) *
1.2,
padding: const EdgeInsets.symmetric(horizontal: MEDIUM_SPACE),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
Expand Down
5 changes: 3 additions & 2 deletions packages/smooth_app/lib/pages/product/simple_input_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:smooth_app/pages/product/may_exit_page_helper.dart';
import 'package:smooth_app/pages/product/simple_input_page_helpers.dart';
import 'package:smooth_app/pages/product/simple_input_widget.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';
import 'package:smooth_app/widgets/will_pop_scope.dart';

/// Simple input page: we have a list of terms, we add, we remove, we save.
class SimpleInputPage extends StatefulWidget {
Expand Down Expand Up @@ -88,8 +89,8 @@ class _SimpleInputPageState extends State<SimpleInputPage> {
);
}

return WillPopScope(
onWillPop: () async => _mayExitPage(saving: false),
return WillPopScope2(
onWillPop: () async => (await _mayExitPage(saving: false), null),
child: UnfocusWhenTapOutside(
child: SmoothScaffold(
fixKeyboard: true,
Expand Down
36 changes: 36 additions & 0 deletions packages/smooth_app/lib/widgets/will_pop_scope.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:flutter/widgets.dart';

/// Brings the same behavior as WillPopScope, which is now deprecated
/// [onWillPop] is a bit different and still asks as the first value if we should block the pop
/// The second value is used, if [Navigator.pop()] should provide a specific value (can be null)
class WillPopScope2 extends StatelessWidget {
const WillPopScope2({
required this.child,
required this.onWillPop,
super.key,
});

final Widget child;
final Future<(bool shouldClose, dynamic res)> Function() onWillPop;

@override
Widget build(BuildContext context) {
return PopScope(
canPop: false,
onPopInvoked: (bool didPop) async {
if (didPop) {
return;
}

final (bool shouldClose, dynamic res) = await onWillPop.call();
if (shouldClose == true) {
WidgetsBinding.instance.addPostFrameCallback((_) {
/// Passing a value is required here, otherwise we will have a black screen
Navigator.of(context).pop(res);
});
}
},
child: child,
);
}
}
Loading

0 comments on commit bccdf1c

Please sign in to comment.