Skip to content

Commit

Permalink
Fixes issue #315
Browse files Browse the repository at this point in the history
Waiting on simc/auto_size_text#35 to be implemented in auto_size_text
  • Loading branch information
giano574 committed Mar 4, 2020
1 parent 9355597 commit aed7eeb
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 19 deletions.
23 changes: 6 additions & 17 deletions lib/screens/weekplan_selector_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:weekplanner/screens/new_weekplan_screen.dart';
import 'package:weekplanner/screens/weekplan_screen.dart';
import 'package:weekplanner/widgets/giraf_app_bar_widget.dart';
import 'package:weekplanner/widgets/giraf_confirm_dialog.dart';
import 'package:weekplanner/widgets/weekyear_row_widget.dart';

/// Screen to select a weekplan for a given user
class WeekplanSelectorScreen extends StatelessWidget {
Expand All @@ -24,6 +25,7 @@ class WeekplanSelectorScreen extends StatelessWidget {

final WeekplansBloc _weekBloc;
final UsernameModel _user;
final AutoSizeGroup _weekYearGroup = AutoSizeGroup();

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -141,23 +143,10 @@ class WeekplanSelectorScreen extends StatelessWidget {
overflow: TextOverflow.ellipsis,
);
})),
Container(
child: weekplan.weekNumber == null
? null
: Expanded(child: LayoutBuilder(builder:
(BuildContext context, BoxConstraints constraints) {
return AutoSizeText(
'Uge: ${weekplan.weekNumber} '
'År: ${weekplan.weekYear}',
key: const Key('weekYear'),
style: const TextStyle(fontSize: 18),
maxLines: 1,
minFontSize: 14,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
);
})),
)
WeekYearRowWidget(
weekplan: weekplan,
autoSizeGroup: _weekYearGroup,
),
],
)),
);
Expand Down
65 changes: 65 additions & 0 deletions lib/widgets/weekyear_row_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import 'package:api_client/models/week_model.dart';
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';

/// Widget for rendering week and year for a week plan.
class WeekYearRowWidget extends StatelessWidget {
/// Renders week and year for [weekplan].
/// Uses [autoSizeGroup] to make sure the font size
/// is consistent across weekplan cards.
const WeekYearRowWidget({
Key key,
@required this.weekplan,
@required this.autoSizeGroup,
}) : super(key: key);

/// The weekplan to show week and year for.
final WeekModel weekplan;

/// The weekplan to show week and year for.
final AutoSizeGroup autoSizeGroup;

@override
Widget build(BuildContext context) {
return Container(
child: weekplan.weekNumber == null
? null
: Expanded(
child: Row(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: AutoSizeText(
'Uge: ${weekplan.weekNumber}',
key: const Key('weekyear_week'),
style: const TextStyle(fontSize: 18),
maxLines: 1,
minFontSize: 8,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
group: autoSizeGroup,
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: AutoSizeText(
'År: ${weekplan.weekYear}',
key: const Key('weekyear_year'),
style: const TextStyle(fontSize: 18),
maxLines: 1,
minFontSize: 8,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
group: autoSizeGroup,
),
),
),
],
),
),
);
}
}
6 changes: 4 additions & 2 deletions test/screens/weekplan_selector_screen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ void main() {
.pumpWidget(MaterialApp(home: WeekplanSelectorScreen(mockUser)));
await tester.pump(Duration.zero);

expect(find.text('Uge: 1 År: 2020'), findsNWidgets(2));
expect(find.byKey(const Key('weekYear')), findsNWidgets(2));
expect(find.text('Uge: 1'), findsNWidgets(2));
expect(find.text('År: 2020'), findsNWidgets(2));
expect(find.byKey(const Key('weekyear_year')), findsNWidgets(2));
expect(find.byKey(const Key('weekyear_week')), findsNWidgets(2));
});

testWidgets('Click on edit icon toggles edit mode',
Expand Down

0 comments on commit aed7eeb

Please sign in to comment.