这是indexloc提供的服务,不要输入任何密码
Skip to content

Optimize Overlay sample to avoid overflow #155861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 60 additions & 55 deletions examples/api/lib/widgets/overlay/overlay.0.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,71 +141,76 @@ class _OverlayExampleState extends State<OverlayExample> {
),
],
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Use Overlay to highlight a NavigationBar destination',
style: Theme.of(context).textTheme.bodyMedium,
),
const SizedBox(height: 20.0),
Row(
body: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
spacing: 10.0,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// This creates a highlight Overlay for
// the Explore item.
ElevatedButton(
onPressed: () {
setState(() {
currentPageIndex = 0;
});
createHighlightOverlay(
alignment: AlignmentDirectional.bottomStart,
borderColor: Colors.red,
);
},
child: const Text('Explore'),
Text(
'Use Overlay to highlight a NavigationBar destination',
style: Theme.of(context).textTheme.bodyMedium,
),
const SizedBox(width: 20.0),
// This creates a highlight Overlay for
// the Commute item.
ElevatedButton(
onPressed: () {
setState(() {
currentPageIndex = 1;
});
createHighlightOverlay(
alignment: AlignmentDirectional.bottomCenter,
borderColor: Colors.green,
);
},
child: const Text('Commute'),
Wrap(
spacing: 10.0,
runSpacing: 10.0,
alignment: WrapAlignment.center,
runAlignment: WrapAlignment.center,
children: <Widget>[
// This creates a highlight Overlay for
// the Explore item.
ElevatedButton(
onPressed: () {
setState(() {
currentPageIndex = 0;
});
createHighlightOverlay(
alignment: AlignmentDirectional.bottomStart,
borderColor: Colors.red,
);
},
child: const Text('Explore'),
),
// This creates a highlight Overlay for
// the Commute item.
ElevatedButton(
onPressed: () {
setState(() {
currentPageIndex = 1;
});
createHighlightOverlay(
alignment: AlignmentDirectional.bottomCenter,
borderColor: Colors.green,
);
},
child: const Text('Commute'),
),
// This creates a highlight Overlay for
// the Saved item.
ElevatedButton(
onPressed: () {
setState(() {
currentPageIndex = 2;
});
createHighlightOverlay(
alignment: AlignmentDirectional.bottomEnd,
borderColor: Colors.orange,
);
},
child: const Text('Saved'),
),
],
),
const SizedBox(width: 20.0),
// This creates a highlight Overlay for
// the Saved item.
ElevatedButton(
onPressed: () {
setState(() {
currentPageIndex = 2;
});
createHighlightOverlay(
alignment: AlignmentDirectional.bottomEnd,
borderColor: Colors.orange,
);
removeHighlightOverlay();
},
child: const Text('Saved'),
child: const Text('Remove Overlay'),
),
],
),
const SizedBox(height: 10.0),
ElevatedButton(
onPressed: () {
removeHighlightOverlay();
},
child: const Text('Remove Overlay'),
),
],
),
),
);
}
Expand Down
15 changes: 15 additions & 0 deletions examples/api/test/widgets/overlay/overlay.0_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,19 @@ void main() {
expect(find.text(commutePage), findsNothing);
expect(find.text(savedPage), findsNothing);
});

testWidgets('Narrow layout does not overflow', (WidgetTester tester) async {
// Set a narrow screen size.
tester.view
..physicalSize = const Size(320, 480)
..devicePixelRatio = 1;
addTearDown(tester.view.reset);

await tester.pumpWidget(
const example.OverlayApp(),
);

// Verify that no overflow errors occur.
expect(tester.takeException(), isNull);
});
}