Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
76df7368
Unverified
Commit
76df7368
authored
Jul 29, 2022
by
Taha Tesser
Committed by
GitHub
Jul 29, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Chips examples and rename files (#108538)
parent
8da73f72
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
422 additions
and
128 deletions
+422
-128
action_chip.0.dart
examples/api/lib/material/action_chip/action_chip.0.dart
+52
-0
choice_chip.0.dart
examples/api/lib/material/choice_chip/choice_chip.0.dart
+70
-0
filter_chip.0.dart
examples/api/lib/material/filter_chip/filter_chip.0.dart
+79
-0
input_chip.0.dart
examples/api/lib/material/input_chip/input_chip.0.dart
+86
-0
action_chip.0_test.dart
...les/api/test/material/action_chip/action_chip.0_test.dart
+22
-0
choice_chip.0_test.dart
...les/api/test/material/choice_chip/choice_chip.0_test.dart
+24
-0
filter_chip.0_test.dart
...les/api/test/material/filter_chip/filter_chip.0_test.dart
+36
-0
input_chip.0_test.dart
examples/api/test/material/input_chip/input_chip.0_test.dart
+33
-0
material.dart
packages/flutter/lib/material.dart
+4
-4
action_chip.dart
packages/flutter/lib/src/material/action_chip.dart
+4
-13
chip.dart
packages/flutter/lib/src/material/chip.dart
+0
-3
choice_chip.dart
packages/flutter/lib/src/material/choice_chip.dart
+4
-33
filter_chip.dart
packages/flutter/lib/src/material/filter_chip.dart
+3
-62
input_chip.dart
packages/flutter/lib/src/material/input_chip.dart
+5
-13
No files found.
examples/api/lib/material/action_chip/action_chip.0.dart
0 → 100644
View file @
76df7368
// 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.
// Flutter code sample ActionChip
import
'package:flutter/material.dart'
;
void
main
(
)
=>
runApp
(
const
ChipApp
());
class
ChipApp
extends
StatelessWidget
{
const
ChipApp
({
super
.
key
});
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
theme:
ThemeData
(
colorSchemeSeed:
const
Color
(
0xff6750a4
),
useMaterial3:
true
),
home:
const
ActionChipExample
(),
);
}
}
class
ActionChipExample
extends
StatefulWidget
{
const
ActionChipExample
({
super
.
key
});
@override
State
<
ActionChipExample
>
createState
()
=>
_ActionChipExampleState
();
}
class
_ActionChipExampleState
extends
State
<
ActionChipExample
>
{
bool
favorite
=
false
;
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'ActionChip Sample'
),
),
body:
Center
(
child:
ActionChip
(
avatar:
Icon
(
favorite
?
Icons
.
favorite
:
Icons
.
favorite_border
),
label:
const
Text
(
'Save to favorites'
),
onPressed:
()
{
setState
(()
{
favorite
=
!
favorite
;
});
},
),
),
);
}
}
examples/api/lib/material/choice_chip/choice_chip.0.dart
0 → 100644
View file @
76df7368
// 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.
// Flutter code sample ActionChoice
import
'package:flutter/material.dart'
;
void
main
(
)
=>
runApp
(
const
ChipApp
());
class
ChipApp
extends
StatelessWidget
{
const
ChipApp
({
super
.
key
});
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
theme:
ThemeData
(
colorSchemeSeed:
const
Color
(
0xff6750a4
),
useMaterial3:
true
),
home:
const
ActionChoiceExample
(),
);
}
}
class
ActionChoiceExample
extends
StatefulWidget
{
const
ActionChoiceExample
({
super
.
key
});
@override
State
<
ActionChoiceExample
>
createState
()
=>
_ActionChoiceExampleState
();
}
class
_ActionChoiceExampleState
extends
State
<
ActionChoiceExample
>
{
int
?
_value
=
1
;
@override
Widget
build
(
BuildContext
context
)
{
final
TextTheme
textTheme
=
Theme
.
of
(
context
).
textTheme
;
return
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'ActionChoice Sample'
),
),
body:
Center
(
child:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
Text
(
'Choose an item'
,
style:
textTheme
.
labelLarge
),
const
SizedBox
(
height:
10.0
),
Wrap
(
spacing:
5.0
,
children:
List
<
Widget
>.
generate
(
3
,
(
int
index
)
{
return
ChoiceChip
(
label:
Text
(
'Item
$index
'
),
selected:
_value
==
index
,
onSelected:
(
bool
selected
)
{
setState
(()
{
_value
=
selected
?
index
:
null
;
});
},
);
},
).
toList
(),
),
],
),
),
);
}
}
examples/api/lib/material/filter_chip/filter_chip.0.dart
0 → 100644
View file @
76df7368
// 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.
// Flutter code sample FilterChip
import
'package:flutter/material.dart'
;
enum
ExerciseFilter
{
walking
,
running
,
cycling
,
hiking
}
void
main
(
)
=>
runApp
(
const
ChipApp
());
class
ChipApp
extends
StatelessWidget
{
const
ChipApp
({
super
.
key
});
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
theme:
ThemeData
(
colorSchemeSeed:
const
Color
(
0xff6750a4
),
useMaterial3:
true
),
home:
const
FilterChipExample
(),
);
}
}
class
FilterChipExample
extends
StatefulWidget
{
const
FilterChipExample
({
super
.
key
});
@override
State
<
FilterChipExample
>
createState
()
=>
_FilterChipExampleState
();
}
class
_FilterChipExampleState
extends
State
<
FilterChipExample
>
{
bool
favorite
=
false
;
final
List
<
String
>
_filters
=
<
String
>[];
@override
Widget
build
(
BuildContext
context
)
{
final
TextTheme
textTheme
=
Theme
.
of
(
context
).
textTheme
;
return
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'FilterChip Sample'
),
),
body:
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
Text
(
'Choose an execise'
,
style:
textTheme
.
labelLarge
),
const
SizedBox
(
height:
5.0
),
Wrap
(
spacing:
5.0
,
children:
ExerciseFilter
.
values
.
map
((
ExerciseFilter
exercise
)
{
return
FilterChip
(
label:
Text
(
exercise
.
name
),
selected:
_filters
.
contains
(
exercise
.
name
),
onSelected:
(
bool
value
)
{
setState
(()
{
if
(
value
)
{
if
(!
_filters
.
contains
(
exercise
.
name
))
{
_filters
.
add
(
exercise
.
name
);
}
}
else
{
_filters
.
removeWhere
((
String
name
)
{
return
name
==
exercise
.
name
;
});
}
});
},
);
}).
toList
(),
),
const
SizedBox
(
height:
10.0
),
Text
(
'Looking for:
${_filters.join(', ')}
'
)
],
),
),
);
}
}
examples/api/lib/material/input_chip/input_chip.0.dart
0 → 100644
View file @
76df7368
// 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.
// Flutter code sample InputChip
import
'package:flutter/material.dart'
;
void
main
(
)
=>
runApp
(
const
ChipApp
());
class
ChipApp
extends
StatelessWidget
{
const
ChipApp
({
super
.
key
});
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
theme:
ThemeData
(
colorSchemeSeed:
const
Color
(
0xff6750a4
),
useMaterial3:
true
),
home:
const
InputChipExample
(),
);
}
}
class
InputChipExample
extends
StatefulWidget
{
const
InputChipExample
({
super
.
key
});
@override
State
<
InputChipExample
>
createState
()
=>
_InputChipExampleState
();
}
class
_InputChipExampleState
extends
State
<
InputChipExample
>
{
int
inputs
=
3
;
int
?
selectedIndex
;
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'InputChip Sample'
),
),
body:
Center
(
child:
Column
(
mainAxisSize:
MainAxisSize
.
min
,
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
Wrap
(
alignment:
WrapAlignment
.
center
,
spacing:
5.0
,
children:
List
<
Widget
>.
generate
(
inputs
,
(
int
index
)
{
return
InputChip
(
label:
Text
(
'Person
${index + 1}
'
),
selected:
selectedIndex
==
index
,
onSelected:
(
bool
selected
)
{
setState
(()
{
if
(
selectedIndex
==
index
)
{
selectedIndex
=
null
;
}
else
{
selectedIndex
=
index
;
}
});
},
onDeleted:
()
{
setState
(()
{
inputs
=
inputs
-
1
;
});
},
);
},
).
toList
(),
),
const
SizedBox
(
height:
10
),
ElevatedButton
(
onPressed:
()
{
setState
(()
{
inputs
=
3
;
});
},
child:
const
Text
(
'Reset'
),
)
],
),
),
);
}
}
examples/api/test/material/action_chip/action_chip.0_test.dart
0 → 100644
View file @
76df7368
// 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/material/action_chip/action_chip.0.dart'
as
example
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
testWidgets
(
'ActionChip updates avatar when tapped'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
example
.
ChipApp
(),
);
expect
(
find
.
byIcon
(
Icons
.
favorite_border
),
findsOneWidget
);
await
tester
.
tap
(
find
.
byType
(
ActionChip
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
byIcon
(
Icons
.
favorite
),
findsOneWidget
);
});
}
examples/api/test/material/choice_chip/choice_chip.0_test.dart
0 → 100644
View file @
76df7368
// 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/material/choice_chip/choice_chip.0.dart'
as
example
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
testWidgets
(
'Can choose an item using ChoiceChip'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
example
.
ChipApp
(),
);
ChoiceChip
choosenChip
=
tester
.
widget
(
find
.
byType
(
ChoiceChip
).
at
(
1
));
expect
(
choosenChip
.
selected
,
true
);
await
tester
.
tap
(
find
.
byType
(
ChoiceChip
).
at
(
0
));
await
tester
.
pumpAndSettle
();
choosenChip
=
tester
.
widget
(
find
.
byType
(
ChoiceChip
).
at
(
0
));
expect
(
choosenChip
.
selected
,
true
);
});
}
examples/api/test/material/filter_chip/filter_chip.0_test.dart
0 → 100644
View file @
76df7368
// 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/material/filter_chip/filter_chip.0.dart'
as
example
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
testWidgets
(
'Filter exercises using FilterChip'
,
(
WidgetTester
tester
)
async
{
const
String
baseText
=
'Looking for: '
;
await
tester
.
pumpWidget
(
const
example
.
ChipApp
(),
);
expect
(
find
.
text
(
baseText
),
findsOneWidget
);
FilterChip
filterChip
=
tester
.
widget
(
find
.
byType
(
FilterChip
).
at
(
2
));
expect
(
filterChip
.
selected
,
false
);
await
tester
.
tap
(
find
.
byType
(
FilterChip
).
at
(
2
));
await
tester
.
pumpAndSettle
();
filterChip
=
tester
.
widget
(
find
.
byType
(
FilterChip
).
at
(
2
));
expect
(
filterChip
.
selected
,
true
);
expect
(
find
.
text
(
'
${baseText}
cycling'
),
findsOneWidget
);
await
tester
.
tap
(
find
.
byType
(
FilterChip
).
at
(
3
));
await
tester
.
pumpAndSettle
();
filterChip
=
tester
.
widget
(
find
.
byType
(
FilterChip
).
at
(
3
));
expect
(
filterChip
.
selected
,
true
);
expect
(
find
.
text
(
'
${baseText}
cycling, hiking'
),
findsOneWidget
);
});
}
examples/api/test/material/input_chip/input_chip.0_test.dart
0 → 100644
View file @
76df7368
// 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/material/input_chip/input_chip.0.dart'
as
example
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
testWidgets
(
''
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
example
.
ChipApp
(),
);
expect
(
find
.
byType
(
InputChip
),
findsNWidgets
(
3
));
await
tester
.
tap
(
find
.
byIcon
(
Icons
.
clear
).
at
(
0
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
InputChip
),
findsNWidgets
(
2
));
await
tester
.
tap
(
find
.
byIcon
(
Icons
.
clear
).
at
(
0
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
InputChip
),
findsNWidgets
(
1
));
await
tester
.
tap
(
find
.
byIcon
(
Icons
.
clear
).
at
(
0
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
InputChip
),
findsNWidgets
(
0
));
await
tester
.
tap
(
find
.
text
(
'Reset'
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
InputChip
),
findsNWidgets
(
3
));
});
}
packages/flutter/lib/material.dart
View file @
76df7368
...
...
@@ -21,6 +21,7 @@
library
material
;
export
'src/material/about.dart'
;
export
'src/material/action_chip.dart'
;
export
'src/material/animated_icons.dart'
;
export
'src/material/app.dart'
;
export
'src/material/app_bar.dart'
;
...
...
@@ -49,11 +50,8 @@ export 'src/material/checkbox.dart';
export
'src/material/checkbox_list_tile.dart'
;
export
'src/material/checkbox_theme.dart'
;
export
'src/material/chip.dart'
;
export
'src/material/chip_action.dart'
;
export
'src/material/chip_choice.dart'
;
export
'src/material/chip_filter.dart'
;
export
'src/material/chip_input.dart'
;
export
'src/material/chip_theme.dart'
;
export
'src/material/choice_chip.dart'
;
export
'src/material/circle_avatar.dart'
;
export
'src/material/color_scheme.dart'
;
export
'src/material/colors.dart'
;
...
...
@@ -82,6 +80,7 @@ export 'src/material/expansion_panel.dart';
export
'src/material/expansion_tile.dart'
;
export
'src/material/expansion_tile_theme.dart'
;
export
'src/material/feedback.dart'
;
export
'src/material/filter_chip.dart'
;
export
'src/material/flexible_space_bar.dart'
;
export
'src/material/floating_action_button.dart'
;
export
'src/material/floating_action_button_location.dart'
;
...
...
@@ -98,6 +97,7 @@ export 'src/material/ink_sparkle.dart';
export
'src/material/ink_splash.dart'
;
export
'src/material/ink_well.dart'
;
export
'src/material/input_border.dart'
;
export
'src/material/input_chip.dart'
;
export
'src/material/input_date_picker_form_field.dart'
;
export
'src/material/input_decorator.dart'
;
export
'src/material/list_tile.dart'
;
...
...
packages/flutter/lib/src/material/
chip_action
.dart
→
packages/flutter/lib/src/material/
action_chip
.dart
View file @
76df7368
...
...
@@ -30,20 +30,11 @@ import 'theme_data.dart';
///
/// Requires one of its ancestors to be a [Material] widget.
///
/// {@tool snippet}
/// {@tool dartpad}
/// This example shows how to create an [ActionChip] with a leading icon.
/// The icon is updated when the [ActionChip] is pressed.
///
/// ```dart
/// ActionChip(
/// avatar: CircleAvatar(
/// backgroundColor: Colors.grey.shade800,
/// child: const Text('AB'),
/// ),
/// label: const Text('Aaron Burr'),
/// onPressed: () {
/// print('If you stand for nothing, Burr, what’ll you fall for?');
/// }
/// )
/// ```
/// ** See code in examples/api/lib/material/action_chip/action_chip.0.dart **
/// {@end-tool}
///
/// ## Material Design 3
...
...
packages/flutter/lib/src/material/chip.dart
View file @
76df7368
...
...
@@ -1310,9 +1310,6 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
child:
result
,
),
);
// if (height != null) {
// result = SizedBox(height: height, child: result);
// }
return
Semantics
(
button:
widget
.
tapEnabled
,
container:
true
,
...
...
packages/flutter/lib/src/material/ch
ip_choice
.dart
→
packages/flutter/lib/src/material/ch
oice_chip
.dart
View file @
76df7368
...
...
@@ -19,40 +19,11 @@ import 'theme_data.dart';
/// Requires one of its ancestors to be a [Material] widget. The [selected] and
/// [label] arguments must not be null.
///
/// {@tool snippet}
/// {@tool dartpad}
/// This example shows how to create [ChoiceChip]s with [onSelected]. When the
/// user taps, the chip will be selected.
///
/// ```dart
/// class MyThreeOptions extends StatefulWidget {
/// const MyThreeOptions({super.key});
///
/// @override
/// State<MyThreeOptions> createState() => _MyThreeOptionsState();
/// }
///
/// class _MyThreeOptionsState extends State<MyThreeOptions> {
/// int? _value = 1;
///
/// @override
/// Widget build(BuildContext context) {
/// return Wrap(
/// children: List<Widget>.generate(
/// 3,
/// (int index) {
/// return ChoiceChip(
/// label: Text('Item $index'),
/// selected: _value == index,
/// onSelected: (bool selected) {
/// setState(() {
/// _value = selected ? index : null;
/// });
/// },
/// );
/// },
/// ).toList(),
/// );
/// }
/// }
/// ```
/// ** See code in examples/api/lib/material/choice_chip/choice_chip.0.dart **
/// {@end-tool}
///
/// ## Material Design 3
...
...
packages/flutter/lib/src/material/
chip_filter
.dart
→
packages/flutter/lib/src/material/
filter_chip
.dart
View file @
76df7368
...
...
@@ -21,69 +21,10 @@ import 'theme_data.dart';
///
/// Requires one of its ancestors to be a [Material] widget.
///
/// {@tool snippet}
/// {@tool dartpad}
/// This example shows how to use [FilterChip]s to filter through exercises.
///
/// ```dart
/// class ActorFilterEntry {
/// const ActorFilterEntry(this.name, this.initials);
/// final String name;
/// final String initials;
/// }
///
/// class CastFilter extends StatefulWidget {
/// const CastFilter({super.key});
///
/// @override
/// State createState() => CastFilterState();
/// }
///
/// class CastFilterState extends State<CastFilter> {
/// final List<ActorFilterEntry> _cast = <ActorFilterEntry>[
/// const ActorFilterEntry('Aaron Burr', 'AB'),
/// const ActorFilterEntry('Alexander Hamilton', 'AH'),
/// const ActorFilterEntry('Eliza Hamilton', 'EH'),
/// const ActorFilterEntry('James Madison', 'JM'),
/// ];
/// final List<String> _filters = <String>[];
///
/// Iterable<Widget> get actorWidgets {
/// return _cast.map((ActorFilterEntry actor) {
/// return Padding(
/// padding: const EdgeInsets.all(4.0),
/// child: FilterChip(
/// avatar: CircleAvatar(child: Text(actor.initials)),
/// label: Text(actor.name),
/// selected: _filters.contains(actor.name),
/// onSelected: (bool value) {
/// setState(() {
/// if (value) {
/// _filters.add(actor.name);
/// } else {
/// _filters.removeWhere((String name) {
/// return name == actor.name;
/// });
/// }
/// });
/// },
/// ),
/// );
/// });
/// }
///
/// @override
/// Widget build(BuildContext context) {
/// return Column(
/// mainAxisAlignment: MainAxisAlignment.center,
/// children: <Widget>[
/// Wrap(
/// children: actorWidgets.toList(),
/// ),
/// Text('Look for: ${_filters.join(', ')}'),
/// ],
/// );
/// }
/// }
/// ```
/// ** See code in examples/api/lib/material/filter_chip/filter_chip.0.dart **
/// {@end-tool}
///
/// ## Material Design 3
...
...
packages/flutter/lib/src/material/
chip_input
.dart
→
packages/flutter/lib/src/material/
input_chip
.dart
View file @
76df7368
...
...
@@ -30,20 +30,12 @@ import 'theme_data.dart';
/// * In a horizontally scrollable list, like a [ListView] whose
/// scrollDirection is [Axis.horizontal].
///
/// {@tool snippet}
/// {@tool dartpad}
/// This example shows how to create [InputChip]s with [onSelected] and
/// [onDeleted] callbacks. When the user taps the chip, the chip will be selected.
/// When the user taps the delete icon, the chip will be deleted.
///
/// ```dart
/// InputChip(
/// avatar: CircleAvatar(
/// backgroundColor: Colors.grey.shade800,
/// child: const Text('AB'),
/// ),
/// label: const Text('Aaron Burr'),
/// onPressed: () {
/// print('I am the one thing in life.');
/// }
/// )
/// ```
/// ** See code in examples/api/lib/material/input_chip/input_chip.0.dart **
/// {@end-tool}
///
/// ## Material Design 3
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment