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
575ced6c
Unverified
Commit
575ced6c
authored
Feb 06, 2023
by
Justin McCandless
Committed by
GitHub
Feb 06, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix context menu web examples (#120104)
The context menu examples on the docs site now work on the web.
parent
ec524ed0
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
169 additions
and
18 deletions
+169
-18
context_menu_controller.0.dart
.../lib/material/context_menu/context_menu_controller.0.dart
+26
-2
editable_text_toolbar_builder.0.dart
...aterial/context_menu/editable_text_toolbar_builder.0.dart
+29
-4
editable_text_toolbar_builder.1.dart
...aterial/context_menu/editable_text_toolbar_builder.1.dart
+29
-3
editable_text_toolbar_builder.2.dart
...aterial/context_menu/editable_text_toolbar_builder.2.dart
+29
-4
selectable_region_toolbar_builder.0.dart
...ial/context_menu/selectable_region_toolbar_builder.0.dart
+27
-2
context_menu_controller.0_test.dart
...material/context_menu/context_menu_controller.0_test.dart
+4
-0
editable_text_toolbar_builder.0_test.dart
...al/context_menu/editable_text_toolbar_builder.0_test.dart
+5
-1
editable_text_toolbar_builder.1_test.dart
...al/context_menu/editable_text_toolbar_builder.1_test.dart
+5
-1
editable_text_toolbar_builder.2_test.dart
...al/context_menu/editable_text_toolbar_builder.2_test.dart
+4
-1
selectable_region_toolbar_builder.0_test.dart
...ontext_menu/selectable_region_toolbar_builder.0_test.dart
+4
-0
context_menu_controller.dart
...ages/flutter/lib/src/widgets/context_menu_controller.dart
+5
-0
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+2
-0
No files found.
examples/api/lib/material/context_menu/context_menu_controller.0.dart
View file @
575ced6c
...
...
@@ -7,15 +7,21 @@
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
void
main
(
)
=>
runApp
(
const
MyApp
());
/// A builder that includes an Offset to draw the context menu at.
typedef
ContextMenuBuilder
=
Widget
Function
(
BuildContext
context
,
Offset
offset
);
class
MyApp
extends
State
less
Widget
{
class
MyApp
extends
State
ful
Widget
{
const
MyApp
({
super
.
key
});
@override
State
<
MyApp
>
createState
()
=>
_MyAppState
();
}
class
_MyAppState
extends
State
<
MyApp
>
{
void
_showDialog
(
BuildContext
context
)
{
Navigator
.
of
(
context
).
push
(
DialogRoute
<
void
>(
...
...
@@ -26,6 +32,24 @@ class MyApp extends StatelessWidget {
);
}
@override
void
initState
()
{
super
.
initState
();
// On web, disable the browser's context menu since this example uses a custom
// Flutter-rendered context menu.
if
(
kIsWeb
)
{
BrowserContextMenu
.
disableContextMenu
();
}
}
@override
void
dispose
()
{
if
(
kIsWeb
)
{
BrowserContextMenu
.
enableContextMenu
();
}
super
.
dispose
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
...
...
@@ -58,7 +82,7 @@ class MyApp extends StatelessWidget {
child:
ListView
(
children:
<
Widget
>[
Container
(
height:
20.0
),
const
Text
(
'Right click
or long press anywhere (not just on this text!)
to show the custom menu.'
),
const
Text
(
'Right click
(desktop) or long press (mobile) anywhere, not just on this text,
to show the custom menu.'
),
],
),
),
...
...
examples/api/lib/material/context_menu/editable_text_toolbar_builder.0.dart
View file @
575ced6c
...
...
@@ -6,17 +6,42 @@
// appearance.
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
void
main
(
)
=>
runApp
(
MyApp
());
void
main
(
)
=>
runApp
(
const
MyApp
());
class
MyApp
extends
State
less
Widget
{
MyApp
({
super
.
key
});
class
MyApp
extends
State
ful
Widget
{
const
MyApp
({
super
.
key
});
@override
State
<
MyApp
>
createState
()
=>
_MyAppState
();
}
class
_MyAppState
extends
State
<
MyApp
>
{
final
TextEditingController
_controller
=
TextEditingController
(
text:
'Right click
or long press
to see the menu with custom buttons.'
,
text:
'Right click
(desktop) or long press (mobile)
to see the menu with custom buttons.'
,
);
@override
void
initState
()
{
super
.
initState
();
// On web, disable the browser's context menu since this example uses a custom
// Flutter-rendered context menu.
if
(
kIsWeb
)
{
BrowserContextMenu
.
disableContextMenu
();
}
}
@override
void
dispose
()
{
if
(
kIsWeb
)
{
BrowserContextMenu
.
enableContextMenu
();
}
super
.
dispose
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
...
...
examples/api/lib/material/context_menu/editable_text_toolbar_builder.1.dart
View file @
575ced6c
...
...
@@ -5,15 +5,23 @@
// This example demonstrates showing a custom context menu only when some
// narrowly defined text is selected.
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
void
main
(
)
=>
runApp
(
MyApp
());
void
main
(
)
=>
runApp
(
const
MyApp
());
const
String
emailAddress
=
'me@example.com'
;
const
String
text
=
'Select the email address and open the menu:
$emailAddress
'
;
class
MyApp
extends
StatelessWidget
{
MyApp
({
super
.
key
});
class
MyApp
extends
StatefulWidget
{
const
MyApp
({
super
.
key
});
@override
State
<
MyApp
>
createState
()
=>
_MyAppState
();
}
class
_MyAppState
extends
State
<
MyApp
>
{
final
TextEditingController
_controller
=
TextEditingController
(
text:
text
,
...
...
@@ -29,6 +37,24 @@ class MyApp extends StatelessWidget {
);
}
@override
void
initState
()
{
super
.
initState
();
// On web, disable the browser's context menu since this example uses a custom
// Flutter-rendered context menu.
if
(
kIsWeb
)
{
BrowserContextMenu
.
disableContextMenu
();
}
}
@override
void
dispose
()
{
if
(
kIsWeb
)
{
BrowserContextMenu
.
enableContextMenu
();
}
super
.
dispose
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
...
...
examples/api/lib/material/context_menu/editable_text_toolbar_builder.2.dart
View file @
575ced6c
...
...
@@ -5,17 +5,42 @@
// This example demonstrates how to create a custom toolbar that retains the
// look of the default buttons for the current platform.
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
void
main
(
)
=>
runApp
(
MyApp
());
void
main
(
)
=>
runApp
(
const
MyApp
());
class
MyApp
extends
State
less
Widget
{
MyApp
({
super
.
key
});
class
MyApp
extends
State
ful
Widget
{
const
MyApp
({
super
.
key
});
@override
State
<
MyApp
>
createState
()
=>
_MyAppState
();
}
class
_MyAppState
extends
State
<
MyApp
>
{
final
TextEditingController
_controller
=
TextEditingController
(
text:
'Right click
or long press
to see the menu with a custom toolbar.'
,
text:
'Right click
(desktop) or long press (mobile)
to see the menu with a custom toolbar.'
,
);
@override
void
initState
()
{
super
.
initState
();
// On web, disable the browser's context menu since this example uses a custom
// Flutter-rendered context menu.
if
(
kIsWeb
)
{
BrowserContextMenu
.
disableContextMenu
();
}
}
@override
void
dispose
()
{
if
(
kIsWeb
)
{
BrowserContextMenu
.
enableContextMenu
();
}
super
.
dispose
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
...
...
examples/api/lib/material/context_menu/selectable_region_toolbar_builder.0.dart
View file @
575ced6c
...
...
@@ -5,15 +5,22 @@
// This example demonstrates a custom context menu in non-editable text using
// SelectionArea.
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
void
main
(
)
=>
runApp
(
const
MyApp
());
const
String
text
=
'I am some text inside of SelectionArea. Right click
or long press
me to show the customized context menu.'
;
const
String
text
=
'I am some text inside of SelectionArea. Right click
(desktop) or long press (mobile)
me to show the customized context menu.'
;
class
MyApp
extends
State
less
Widget
{
class
MyApp
extends
State
ful
Widget
{
const
MyApp
({
super
.
key
});
@override
State
<
MyApp
>
createState
()
=>
_MyAppState
();
}
class
_MyAppState
extends
State
<
MyApp
>
{
void
_showDialog
(
BuildContext
context
)
{
Navigator
.
of
(
context
).
push
(
DialogRoute
<
void
>(
...
...
@@ -24,6 +31,24 @@ class MyApp extends StatelessWidget {
);
}
@override
void
initState
()
{
super
.
initState
();
// On web, disable the browser's context menu since this example uses a custom
// Flutter-rendered context menu.
if
(
kIsWeb
)
{
BrowserContextMenu
.
disableContextMenu
();
}
}
@override
void
dispose
()
{
if
(
kIsWeb
)
{
BrowserContextMenu
.
enableContextMenu
();
}
super
.
dispose
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
...
...
examples/api/test/material/context_menu/context_menu_controller.0_test.dart
View file @
575ced6c
...
...
@@ -2,8 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/foundation.dart'
;
import
'package:flutter/gestures.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter_api_samples/material/context_menu/context_menu_controller.0.dart'
as
example
;
import
'package:flutter_test/flutter_test.dart'
;
...
...
@@ -13,6 +15,8 @@ void main() {
const
example
.
MyApp
(),
);
expect
(
BrowserContextMenu
.
enabled
,
!
kIsWeb
);
expect
(
find
.
byType
(
AdaptiveTextSelectionToolbar
),
findsNothing
);
// Right clicking the middle of the app shows the custom context menu.
...
...
examples/api/test/material/context_menu/editable_text_toolbar_builder.0_test.dart
View file @
575ced6c
...
...
@@ -3,16 +3,20 @@
// found in the LICENSE file.
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter_api_samples/material/context_menu/editable_text_toolbar_builder.0.dart'
as
example
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
testWidgets
(
'showing and hiding the context menu in TextField with custom buttons'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
example
.
MyApp
(),
const
example
.
MyApp
(),
);
expect
(
BrowserContextMenu
.
enabled
,
!
kIsWeb
);
await
tester
.
tap
(
find
.
byType
(
EditableText
));
await
tester
.
pump
();
...
...
examples/api/test/material/context_menu/editable_text_toolbar_builder.1_test.dart
View file @
575ced6c
...
...
@@ -2,17 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/foundation.dart'
;
import
'package:flutter/gestures.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter_api_samples/material/context_menu/editable_text_toolbar_builder.1.dart'
as
example
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
testWidgets
(
'showing and hiding the custom context menu in TextField with a specific selection'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
example
.
MyApp
(),
const
example
.
MyApp
(),
);
expect
(
BrowserContextMenu
.
enabled
,
!
kIsWeb
);
expect
(
find
.
byType
(
AdaptiveTextSelectionToolbar
),
findsNothing
);
// Right clicking the Text in the TextField shows the custom context menu,
...
...
examples/api/test/material/context_menu/editable_text_toolbar_builder.2_test.dart
View file @
575ced6c
...
...
@@ -5,15 +5,18 @@
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter_api_samples/material/context_menu/editable_text_toolbar_builder.2.dart'
as
example
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
testWidgets
(
'showing and hiding the context menu in TextField with a custom toolbar'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
example
.
MyApp
(),
const
example
.
MyApp
(),
);
expect
(
BrowserContextMenu
.
enabled
,
!
kIsWeb
);
await
tester
.
tap
(
find
.
byType
(
EditableText
));
await
tester
.
pump
();
...
...
examples/api/test/material/context_menu/selectable_region_toolbar_builder.0_test.dart
View file @
575ced6c
...
...
@@ -2,8 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/foundation.dart'
;
import
'package:flutter/gestures.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter_api_samples/material/context_menu/selectable_region_toolbar_builder.0.dart'
as
example
;
import
'package:flutter_test/flutter_test.dart'
;
...
...
@@ -13,6 +15,8 @@ void main() {
const
example
.
MyApp
(),
);
expect
(
BrowserContextMenu
.
enabled
,
!
kIsWeb
);
// Allow the selection overlay geometry to be created.
await
tester
.
pump
();
...
...
packages/flutter/lib/src/widgets/context_menu_controller.dart
View file @
575ced6c
...
...
@@ -18,6 +18,11 @@ import 'overlay.dart';
///
/// ** See code in examples/api/lib/material/context_menu/context_menu_controller.0.dart **
/// {@end-tool}
///
/// See also:
///
/// * [BrowserContextMenu], which allows the browser's context menu on web to
/// be disabled and Flutter-rendered context menus to appear.
class
ContextMenuController
{
/// Creates a context menu that can be shown with [show].
ContextMenuController
({
...
...
packages/flutter/lib/src/widgets/editable_text.dart
View file @
575ced6c
...
...
@@ -1773,6 +1773,8 @@ class EditableText extends StatefulWidget {
/// * [AdaptiveTextSelectionToolbar.getAdaptiveButtons], which builds the
/// button Widgets for the current platform given
/// [ContextMenuButtonItem]s.
/// * [BrowserContextMenu], which allows the browser's context menu on web
/// to be disabled and Flutter-rendered context menus to appear.
/// {@endtemplate}
///
/// If not provided, no context menu will be shown.
...
...
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