सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
context_menus पैकेज डेवलपर्स को उपयोगकर्ताओं द्वारा राइट-क्लिक या लॉन्ग-प्रेस गतिविधि करने पर फ्लटर ऐप में संदर्भ मेनू प्रदर्शित करने की अनुमति देता है। यह मोबाइल, वेब और डेस्कटॉप सहित कई प्लेटफॉर्म पर मेनू विकल्प प्रस्तुत करने का एक संगत और कस्टमाइज़ करने योग्य तरीका प्रदान करता है। पैकेज फ्लटर के विजेट सिस्टम के साथ बिना किसी बाधा के एकीकृत है और टच और पॉइंटर-आधारित इंटरैक्शन का समर्थन करता है। उपयोग में आसान डिज़ाइन के कारण, इसमें जटिल कस्टम लॉजिक के बिना संदर्भ कार्यों को तेजी से लागू करने की अनुमति है। संदर्भ-संवेदनशील मेनू के माध्यम से स्पष्ट उपयोगकर्ता अंतरक्रिया की आवश्यकता वाले एप्लिकेशन के लिए आदर्श है।
उपयोग
डेस्कटॉप पर राइट-क्लिक कंटेक्स्ट मेनू
मोबाइल पर लंबे समय तक मेनू दबाएं
प्लेटफॉर्म-संगत यूआई इंटरैक्शन
कस्टमाइज़ करने योग्य क्रिया पैनल
सुधारित उपयोगकर्ता कार्य प्रवाह
इंटरैक्टिव एप तत्व
मुख्य विशेषताएँ
प्लेटफॉर्म के अनुकूल समर्थन
दाहिने क्लिक और लंबे समय तक दबाए रखने से ट्रिगर होता है
कस्टमाइज़ेबल मेनू आइटम
सरल API एकीकरण
प्रतिक्रियाशील डिज़ाइन संगतता
निर्मित प्लेटफॉर्म स्टाइलिंग
इनके लिए उपयुक्त
डेस्कटॉप और मोबाइल ऐप डेवलपर्स
UI-भारी एप्लिकेशन
संदर्भ क्रिया इंटरफेस
गतिशील मेनू की आवश्यकता वाले ऐप्स
हल्के समाधान खोज रहे विकासकर्ता
विचार योग्य बातें
पॉइंटर इवेंट्स का हैंडलिंग मैनुअल रूप से आवश्यक है
सीमित आंतरिक एनीमेशन
सुसंगतता के लिए अतिरिक्त स्टाइलिंग की आवश्यकता हो सकती है
जटिल नेस्टेड मेनू के लिए उपयुक्त नहीं
सही गेस्चर डिटेक्शन सेटअप पर निर्भर करता है
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
context_menus
A package to show context menus on right-click or long-press.
🔨 Installation
dependencies:context_menus:^1.0.2
⚙ Import
import'package:context_menus/context_menus.dart';
🕹️ Usage
To get started, wrap a ContextMenuOverlay around your top-most view or app:
In this case, you are responsible for closing the menu when your buttons are triggered, which you can do using an extension on BuildContext:
context.contextMenuOverlay.hide();
💡 Custom Menus
The easiest way to create a custom menu is to use the GenericContextMenu. Just pass it a list of ContextMenuButtonConfig instances:
/// Custom Context Menu for an ImageContextMenuRegion(
contextMenu: GenericContextMenu(
buttonConfigs: [
ContextMenuButtonConfig(
"View image in browser",
onPressed: () => launch(_testImageUrl),
),
ContextMenuButtonConfig(
"Copy image path",
onPressed: () => Clipboard.setData(ClipboardData(text: _testImageUrl)),
)
],
),
child: Image.network(_testImageUrl),
),
Another easy way to create custom menus is to use the ContextMenuStateMixin, and then call the cardBuilder and buttonBuilder methods to create your commands.
You can see this in action with the existing LinkContextMenu:
class_LinkContextMenuStateextendsState<LinkContextMenu> withContextMenuStateMixin{
@overrideWidgetbuild(BuildContext context) {
// cardBuilder is provided to us by the mixin, pass it a list of children to layoutreturn cardBuilder.call(
context,
[
// buttonBuilder is also provided by the mixin, use it to build each btn
buttonBuilder.call(
context,
// button builder needs a config, so it knows how to setup the btnContextMenuButtonConfig(
"Open link in new window",
icon: widget.useIcons ? Icon(Icons.link, size: 18) : null,
onPressed: () => handlePressed(context, _handleNewWindowPressed),
),
),
buttonBuilder.call(
context,
ContextMenuButtonConfig(
"Copy link address",
icon: widget.useIcons ? Icon(Icons.copy, size: 18) : null,
onPressed: () => handlePressed(context, _handleClipboardPressed),
),
)
],
);
}
In the above example, you could provide your own Card and Buttons directly, rather than using the builders, but the builders give you a couple of advantages:
You can style all menus using the button and card builders on the ContextMenuOverlay
All buttons will auto-close the context menu when triggered, saving you some boilerplate
Your custom menus will match the existing set of menus
🐞 Bugs/Requests
If you encounter any problems please open an issue. If you feel the library is missing a feature, please raise a ticket on Github and we'll look into it. Pull request are welcome.