mirror of
https://github.com/flutter/samples.git
synced 2026-03-27 06:41:37 +00:00
Custom context menu example (#1463)
* flutter create * Copied in from 'contextual-menu-examples' repo * Works again with the latest updates to the branch * Clean up anywhere example * Clean up other examples * Add to CI * Updated with release version of context menus, and added platform switcher * Generated files * Home icon on your original platform * Remove web_dashboard from ci, not sure why that change was there... * Add context_menu to beta channel, but commented out, for the future * +x permissions on the master script, which I may have accidentally changed before? * Actual bash comment * dart format * Natural default platform' * A working test, for the email page * Import order fix * Test some pages * More tests * dart format
This commit is contained in:
committed by
GitHub
parent
070ce7303a
commit
41571eae07
46
experimental/context_menus/test/utils.dart
Normal file
46
experimental/context_menus/test/utils.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
// Returns the first RenderEditable.
|
||||
RenderEditable findRenderEditable(WidgetTester tester) {
|
||||
final RenderObject root = tester.renderObject(find.byType(EditableText));
|
||||
expect(root, isNotNull);
|
||||
|
||||
late RenderEditable renderEditable;
|
||||
void recursiveFinder(RenderObject child) {
|
||||
if (child is RenderEditable) {
|
||||
renderEditable = child;
|
||||
return;
|
||||
}
|
||||
child.visitChildren(recursiveFinder);
|
||||
}
|
||||
|
||||
root.visitChildren(recursiveFinder);
|
||||
expect(renderEditable, isNotNull);
|
||||
return renderEditable;
|
||||
}
|
||||
|
||||
Offset textOffsetToPosition(WidgetTester tester, int offset) {
|
||||
final RenderEditable renderEditable = findRenderEditable(tester);
|
||||
final List<TextSelectionPoint> endpoints = globalize(
|
||||
renderEditable.getEndpointsForSelection(
|
||||
TextSelection.collapsed(offset: offset),
|
||||
),
|
||||
renderEditable,
|
||||
);
|
||||
expect(endpoints.length, 1);
|
||||
return endpoints[0].point + const Offset(kIsWeb ? 1.0 : 0.0, -2.0);
|
||||
}
|
||||
|
||||
List<TextSelectionPoint> globalize(
|
||||
Iterable<TextSelectionPoint> points, RenderBox box) {
|
||||
return points.map<TextSelectionPoint>((TextSelectionPoint point) {
|
||||
return TextSelectionPoint(
|
||||
box.localToGlobal(point.point),
|
||||
point.direction,
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
Reference in New Issue
Block a user