Skip to content

Commit

Permalink
fix: Added text 'compare to category' for the comparison page (#4221)
Browse files Browse the repository at this point in the history
Co-authored-by: Edouard Marquez <moi@edouard-marquez.me>
  • Loading branch information
hsradA23 and g123k committed Jul 22, 2023
1 parent 580b822 commit 899cea6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';

import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:iso_countries/iso_countries.dart';
Expand All @@ -25,18 +24,21 @@ import 'package:smooth_app/pages/product/common/product_list_item_simple.dart';
import 'package:smooth_app/pages/product/common/product_query_page_helper.dart';
import 'package:smooth_app/query/paged_product_query.dart';
import 'package:smooth_app/widgets/ranking_floating_action_button.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

class ProductQueryPage extends StatefulWidget {
const ProductQueryPage({
required this.productListSupplier,
required this.name,
required this.editableAppBarTitle,
this.searchResult = true,
});

final ProductListSupplier productListSupplier;
final String name;
final bool editableAppBarTitle;
final bool searchResult;

@override
State<ProductQueryPage> createState() => _ProductQueryPageState();
Expand Down Expand Up @@ -156,13 +158,16 @@ class _ProductQueryPageState extends State<ProductQueryPage>
? MainAxisAlignment.spaceBetween
: MainAxisAlignment.center,
children: <Widget>[
RankingFloatingActionButton(
onPressed: () => Navigator.push<Widget>(
context,
MaterialPageRoute<Widget>(
builder: (BuildContext context) => PersonalizedRankingPage(
barcodes: _model.displayBarcodes,
title: widget.name,
Padding(
padding: const EdgeInsets.symmetric(vertical: 5.0),
child: RankingFloatingActionButton(
onPressed: () => Navigator.push<Widget>(
context,
MaterialPageRoute<Widget>(
builder: (BuildContext context) => PersonalizedRankingPage(
barcodes: _model.displayBarcodes,
title: widget.name,
),
),
),
),
Expand Down Expand Up @@ -196,15 +201,20 @@ class _ProductQueryPageState extends State<ProductQueryPage>
),
],
),
appBar: AppBar(
appBar: SmoothAppBar(
backgroundColor: themeData.scaffoldBackgroundColor,
elevation: 2,
automaticallyImplyLeading: false,
leading: const SmoothBackButton(),
title: _AppBarTitle(
name: widget.name,
editableAppBarTitle: widget.editableAppBarTitle,
title: widget.searchResult
? widget.name
: appLocalizations.product_search_same_category,
editableAppBarTitle:
widget.searchResult && widget.editableAppBarTitle,
multiLines: !widget.searchResult,
),
subTitle: !widget.searchResult ? Text(widget.name) : null,
actions: _getAppBarButtons(),
),
body: RefreshIndicator(
Expand Down Expand Up @@ -490,7 +500,7 @@ class _EmptyScreen extends StatelessWidget {
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
leading: const SmoothBackButton(),
title: _AppBarTitle(
name: name,
title: name,
editableAppBarTitle: false,
),
actions: actions,
Expand All @@ -502,31 +512,36 @@ class _EmptyScreen extends StatelessWidget {

class _AppBarTitle extends StatelessWidget {
const _AppBarTitle({
required this.name,
required this.title,
this.multiLines = true,
required this.editableAppBarTitle,
Key? key,
}) : super(key: key);

final String name;
final String title;
final bool multiLines;
final bool editableAppBarTitle;

@override
Widget build(BuildContext context) {
final Widget child = AutoSizeText(
name,
maxLines: 2,
final Widget child = Text(
title,
maxLines: multiLines ? 2 : 1,
);

if (editableAppBarTitle) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);

return GestureDetector(
return InkWell(
onTap: () {
Navigator.of(context).pop(ProductQueryPageResult.editProductQuery);
},
child: Tooltip(
message: appLocalizations.tap_to_edit_search,
child: child,
child: SizedBox(
width: double.infinity,
child: child,
),
),
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ProductQueryPageHelper {
required final String name,
required final BuildContext context,
bool editableAppBarTitle = true,
bool searchResult = true,
EditProductQueryCallback? editQueryCallback,
}) async {
final ProductListSupplier supplier =
Expand All @@ -31,6 +32,7 @@ class ProductQueryPageHelper {
productListSupplier: supplier,
name: name,
editableAppBarTitle: editableAppBarTitle,
searchResult: searchResult,
),
),
);
Expand Down
1 change: 1 addition & 0 deletions packages/smooth_app/lib/pages/product/summary_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ class _SummaryCardState extends State<SummaryCard> with UpToDateMixin {
localDatabase: context.read<LocalDatabase>(),
productQuery: CategoryProductQuery(categoryTag!),
context: context,
searchResult: false,
),
),
);
Expand Down

0 comments on commit 899cea6

Please sign in to comment.