-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Updated document to clarify Clip Behaviour #157719
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
auto-submit
merged 17 commits into
flutter:master
from
Neutrino2711:update-documentation
Nov 14, 2024
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fd3b099
update documentation on clipBehavior
Neutrino2711 5113336
added example on clipBehavior
Neutrino2711 69c23ef
Merge branch 'master' into update-documentation
Neutrino2711 af772ab
Trigger CI
Neutrino2711 a7dc7e3
added example
Neutrino2711 001cf0a
Merge branch 'master' into update-documentation
Neutrino2711 f3f9d86
Merge branch 'master' into update-documentation
Neutrino2711 68de1c7
added test for clipping example
Neutrino2711 549912e
Merge remote-tracking branch 'upstream/master' into update-documentation
Neutrino2711 47268f2
Merge branch 'update-documentation' of https://github.com/Neutrino271…
Neutrino2711 f6a1ce1
Apply suggestions from code review
Neutrino2711 6535d48
Merge branch 'master' into update-documentation
Neutrino2711 ba50b4d
Apply suggestions from code review
Neutrino2711 768a8b8
Apply suggestions from code review
Neutrino2711 7173b46
Merge branch 'master' into update-documentation
Neutrino2711 7495c69
added readability changes
Neutrino2711 3f41392
Merge branch 'master' into update-documentation
Neutrino2711 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
158 changes: 158 additions & 0 deletions
158
examples/api/lib/widgets/sliver/decorated_sliver.1.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| // Copyright 2014 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
|
|
||
| /// Flutter code example for [DecoratedSliver] | ||
| /// with clipping turned off in a parent [CustomScrollView]. | ||
|
|
||
| void main() => runApp(const DecoratedSliverClipExampleApp()); | ||
|
|
||
| class DecoratedSliverClipExampleApp extends StatelessWidget { | ||
| const DecoratedSliverClipExampleApp({super.key}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return MaterialApp( | ||
| title: 'DecoratedSliver Clip Example', | ||
| theme: ThemeData( | ||
| colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), | ||
| useMaterial3: true, | ||
| ), | ||
| home: const DecoratedSliverClipExample(), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class DecoratedSliverClipExample extends StatefulWidget { | ||
| const DecoratedSliverClipExample({super.key}); | ||
|
|
||
| @override | ||
| State<DecoratedSliverClipExample> createState() => _DecoratedSliverClipExampleState(); | ||
| } | ||
|
|
||
| class _DecoratedSliverClipExampleState extends State<DecoratedSliverClipExample> { | ||
| double _height = 225.0; | ||
| bool _isClipped = false; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Scaffold( | ||
| backgroundColor: const Color(0xFF1C1C1C), | ||
| body: Column( | ||
| children: <Widget>[ | ||
| Row( | ||
| mainAxisAlignment: MainAxisAlignment.spaceEvenly, | ||
| children: <Widget>[ | ||
| Switch( | ||
| inactiveTrackColor: Colors.cyan, | ||
| activeColor: Colors.pink, | ||
| onChanged: (bool value) { | ||
| setState(() { | ||
| _isClipped = value; | ||
| }); | ||
| }, | ||
| value: _isClipped, | ||
| ), | ||
| Slider( | ||
| activeColor: Colors.pink, | ||
| inactiveColor: Colors.cyan, | ||
| onChanged: (double value) { | ||
| setState(() { | ||
| _height = value; | ||
| }); | ||
| }, | ||
| value: _height, | ||
| min: 150, | ||
| max: 225, | ||
| ), | ||
| ], | ||
| ), | ||
| const SizedBox( | ||
| height: 20.0, | ||
| ), | ||
| Stack( | ||
| children: <Widget>[ | ||
| Padding( | ||
| padding: const EdgeInsets.all(24.0), | ||
| child: SizedBox( | ||
| width: 400, | ||
| height: _height, | ||
| child: ResizableCustomScrollView(isClipped: _isClipped), | ||
| ), | ||
| ), | ||
| Positioned( | ||
| top: _height, | ||
| left: 0, | ||
| right: 0, | ||
| child: SizedBox( | ||
| height: MediaQuery.of(context).size.height - _height, | ||
| width: double.infinity, | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ], | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class ResizableCustomScrollView extends StatelessWidget { | ||
| const ResizableCustomScrollView({ | ||
| super.key, | ||
| required this.isClipped, | ||
| }); | ||
|
|
||
| final bool isClipped; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return CustomScrollView( | ||
| // The clip behavior defaults to Clip.hardEdge if no argument is provided. | ||
| clipBehavior: isClipped ? Clip.hardEdge : Clip.none, | ||
| slivers: <Widget>[ | ||
| DecoratedSliver( | ||
| decoration: const ShapeDecoration( | ||
| color: Color(0xFF2C2C2C), | ||
| shape: RoundedRectangleBorder( | ||
| borderRadius: BorderRadius.all( | ||
| Radius.circular(6), | ||
| ), | ||
| ), | ||
| shadows: <BoxShadow>[ | ||
| BoxShadow( | ||
| color: Colors.cyan, | ||
| offset: Offset(3, 3), | ||
| blurRadius: 24, | ||
| ), | ||
| ], | ||
| ), | ||
| sliver: SliverList.builder( | ||
| itemCount: 5, | ||
| itemBuilder: (_, int index) => Padding( | ||
| padding: const EdgeInsets.all(8.0), | ||
| child: Row( | ||
| children: <Widget>[ | ||
| const Icon( | ||
| Icons.add_box, | ||
| color: Color(0xFFA8A8A8), | ||
| ), | ||
| Flexible( | ||
| child: Text( | ||
| 'Item $index', | ||
| style: const TextStyle( | ||
| color: Color(0xFFA8A8A8), | ||
| ), | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ], | ||
| ); | ||
| } | ||
| } | ||
42 changes: 42 additions & 0 deletions
42
examples/api/test/widgets/sliver/decorated_sliver.1_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright 2014 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_api_samples/widgets/sliver/decorated_sliver.1.dart' as example; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| void main() { | ||
| testWidgets('CustomScrollView clipBehavior is Clip.none when is Clipped is false', (WidgetTester tester) async { | ||
| await tester.pumpWidget( | ||
| const MaterialApp( | ||
| home: example.DecoratedSliverClipExample(), | ||
| ), | ||
| ); | ||
|
|
||
| final CustomScrollView customScrollView = tester.widget(find.byType(CustomScrollView)); | ||
|
|
||
| expect(customScrollView.clipBehavior, equals(Clip.none)); | ||
| }); | ||
|
|
||
| testWidgets('Verify the DecoratedSliver has shadow property in decoration', (WidgetTester tester) async { | ||
| await tester.pumpWidget( | ||
| const MaterialApp( | ||
| home: example.ResizableCustomScrollView(isClipped: false), | ||
| ), | ||
| ); | ||
|
|
||
| final DecoratedSliver decoratedSliver = tester.widget(find.byType(DecoratedSliver)); | ||
| final ShapeDecoration shapeDecoration = decoratedSliver.decoration as ShapeDecoration; | ||
|
|
||
| expect(shapeDecoration.shadows, isNotEmpty); | ||
| }); | ||
|
|
||
| testWidgets('Verify Slider and Switch widgets', (WidgetTester tester) async { | ||
| await tester.pumpWidget(const example.DecoratedSliverClipExampleApp()); | ||
|
|
||
| expect(find.byType(Slider), findsOneWidget); | ||
|
|
||
| expect(find.byType(Switch), findsOneWidget); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.