Skip to content

Commit 970e70d

Browse files
authored
Use go_router for routing and switch to path-based URLs (#180)
This prepares the app to support the cl/<cl number>/<patchset> route it needs to display the aggregated test results. Switching to path based routing means the app will be able to handle the existing URLs used in Gerrit, which will make it easier to transition to the new UI. * Use go_router for routing * Enable use_key_in_widget_constructors lint * Use IconButton tooltip property instead of widget
1 parent 2169a61 commit 970e70d

File tree

15 files changed

+438
-196
lines changed

15 files changed

+438
-196
lines changed

current_results_ui/analysis_options.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ analyzer:
77

88
linter:
99
rules:
10-
# Disabled as there are currently many violations.
11-
use_key_in_widget_constructors: false
1210
# Disabled - currently one violation.
1311
avoid_print: false
1412

current_results_ui/lib/filter.dart

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
import 'package:collection/collection.dart';
66
import 'package:flutter/material.dart';
7+
import 'package:go_router/go_router.dart';
78
import 'package:provider/provider.dart';
89

910
import 'query.dart';
10-
import 'main.dart';
1111

1212
class Filter {
1313
final List<String> terms;
@@ -18,12 +18,16 @@ class Filter {
1818
return List.unmodifiable(termString.split(',').map((s) => s.trim()));
1919
}
2020

21-
bool hasSameTerms(Filter other) =>
22-
const ListEquality().equals(terms, other.terms);
21+
@override
22+
bool operator ==(Object other) =>
23+
other is Filter && const ListEquality().equals(terms, other.terms);
24+
25+
@override
26+
int get hashCode => const ListEquality().hash(terms);
2327
}
2428

2529
class FilterUI extends StatefulWidget {
26-
const FilterUI();
30+
const FilterUI({super.key});
2731

2832
@override
2933
State<FilterUI> createState() => _FilterUIState();
@@ -38,6 +42,14 @@ class _FilterUIState extends State<FilterUI> {
3842
super.dispose();
3943
}
4044

45+
void _updateFilter(Iterable<String> newTerms) {
46+
final uri = GoRouter.of(context).routeInformationProvider.value.uri;
47+
final newUri = uri.replace(
48+
queryParameters: {...uri.queryParameters, 'filter': newTerms.join(',')},
49+
);
50+
GoRouter.of(context).go(newUri.toString());
51+
}
52+
4153
@override
4254
Widget build(BuildContext context) {
4355
return Consumer<QueryResults>(
@@ -62,9 +74,8 @@ class _FilterUIState extends State<FilterUI> {
6274
InputChip(
6375
label: Text(term),
6476
onDeleted: () {
65-
pushRoute(
66-
context,
67-
terms: filter.terms.where((t) => t != term),
77+
_updateFilter(
78+
filter.terms.where((t) => t != term),
6879
);
6980
},
7081
onPressed: () {
@@ -92,9 +103,8 @@ class _FilterUIState extends State<FilterUI> {
92103
term.startsWith(newTerm) || newTerm.startsWith(term),
93104
);
94105
controller.text = '';
95-
pushRoute(
96-
context,
97-
terms: filter.terms
106+
_updateFilter(
107+
filter.terms
98108
.where(isNotReplacedByNewTerm)
99109
.followedBy(newTerms),
100110
);

current_results_ui/lib/instructions.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:flutter/material.dart';
6+
import 'package:go_router/go_router.dart';
67

78
class Instructions extends StatelessWidget {
9+
const Instructions({super.key});
10+
811
@override
912
Widget build(context) {
1013
return SingleChildScrollView(
@@ -47,7 +50,12 @@ class Instructions extends StatelessWidget {
4750
const SizedBox(height: 12),
4851
InkWell(
4952
onTap: () {
50-
Navigator.pushNamed(context, '/filter=${example['terms']}');
53+
GoRouter.of(context).go(
54+
Uri(
55+
path: '/',
56+
queryParameters: {'filter': example['terms']},
57+
).toString(),
58+
);
5159
},
5260
child: Text.rich(
5361
TextSpan(

0 commit comments

Comments
 (0)