|
| 1 | +--- |
| 2 | +id: implementing-plugins |
| 3 | +title: Plugin Implementation |
| 4 | +--- |
| 5 | + |
| 6 | +Plugins are existing features that are wrapped with some special logic or widgets to make them controllable. |
| 7 | + |
| 8 | +Plugin are activated from Plugin store of the Admin panel |
| 9 | + |
| 10 | +To implement features as plugins or to convert existing features into plugins, follow the below steps |
| 11 | + |
| 12 | +## Technical Overview of the Steps to Implement features as plugins |
| 13 | + |
| 14 | +### 1. Plugin Registration |
| 15 | + |
| 16 | +- Plugins have to be registered first before even they are created from the Plugin store in the `Talawa Admin` portal. This can be done by developer by creating an account in the admin portal and going to `Plugin Store`. |
| 17 | +- Plugin Store can be accessed from navbar |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +- Once entered in store , you will see a list of available plugins |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +- Click on the `Add New` Button |
| 26 | +- Enter the Details of the New Plugin and Click on `Create`. |
| 27 | + |
| 28 | +:::caution |
| 29 | + |
| 30 | +The `Name` of plugin provided is very important and will be used for later steps. |
| 31 | +Make sure to use unique names with trailing spaces. |
| 32 | + |
| 33 | +::: |
| 34 | + |
| 35 | +In next step we'll see how to create plugins |
| 36 | + |
| 37 | +### 2. Plugin Creation |
| 38 | + |
| 39 | +Based on where the feature UI is there are currently 2 ways to implement your features as plugins. Let's call them type A and B features for now. |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +#### A. Feature that are located in the bottom navigation bar |
| 44 | + |
| 45 | +- For the features in the navbar we have maintained a list of them in [main_scree.dart](https://github.com/PalisadoesFoundation/talawa/blob/develop/lib/views/main_screen.dart) file.It has detailed comments to help you understand the operations. |
| 46 | + |
| 47 | +- `renderBottomNavBarPlugins` method combines current features and plugins in navbar and generates an array containing `navBarItems` and `navbarClasses` and then it is returned to `children` property of the navbar UI code. |
| 48 | +- Let's understand some important variables before understanding the process of conversion. |
| 49 | + |
| 50 | +:::caution |
| 51 | + |
| 52 | +The `Name` of property provided to any of the below variables should the exactly same for that feature only without any trailing spaces. Duplicate or Existing plugin names shouldn't be used keep the application consistent and predictable. |
| 53 | + |
| 54 | +::: |
| 55 | + |
| 56 | +1. `navBarItems` |
| 57 | + - Type `[ BottomNavigationBarItem() ]` |
| 58 | + - contains list of `BottomNavigationBarItem` widget to show `icon` and `text` to the navbar options. |
| 59 | + - if your feature is not a plugin it should be added to this array. |
| 60 | +2. `navBarClasses` |
| 61 | + - Type `[Widgets]` |
| 62 | + - Array that contains the Widgets to be rendered on the navbar |
| 63 | +3. `navNameClasses` |
| 64 | + - Type ` Map<dynamic, dynamic>` |
| 65 | + - Maps the feature names with their proper Icons and Widgets (named as `class`) used in navbar. |
| 66 | +4. `navNameIcon` |
| 67 | + - Type `Map<String, Widgets>` |
| 68 | + - Contains a key value pair of the feature name in the navbar and it's corresponding plugin. |
| 69 | + |
| 70 | +#### B. Other Features |
| 71 | + |
| 72 | +- `TalawaPluginProvider` is Flutter widget that is used here . The Source can be viewed [here](https://github.com/PalisadoesFoundation/talawa/blob/develop/lib/plugins/talawa_plugin_provider.dart) |
| 73 | +- Here's the basic use of `TalawaPluginProvider` with `Text()` widget.Let's discuss it's properties |
| 74 | + |
| 75 | +```js |
| 76 | + const TalawaPluginProvider(child: Text("Demo") , |
| 77 | + visible: true, |
| 78 | + pluginName: "My Plugin" |
| 79 | + ); |
| 80 | +``` |
| 81 | + |
| 82 | +1. `child` |
| 83 | + |
| 84 | + - Type `Widget?` |
| 85 | + - It can be any flutter UI widget like `Container()`, `Text()`, `Row()`,etc. For example if your features is encapsulated within an `Container()` widget then wrap that widget into the `TalawaPluginProvider` . |
| 86 | + |
| 87 | +2. `visible` |
| 88 | + |
| 89 | + - Type `Boolean` |
| 90 | + - True if plugin is Installed and plugin will be visible, Otherwise false hence plugin is hidden. |
| 91 | + |
| 92 | +3. `pluginName` |
| 93 | + - Type `String` |
| 94 | + - Contains the name of the plugin. Make sure that the name provided here should match with the plugin name registered on the store from the |
| 95 | + [Step 1 A ](#a-feature-that-are-located-in-the-bottom-navigation-bar) |
| 96 | + - For example. If plugin stored on the store as `Members List` then here exactly enter `Members List` without any trialing spaces. |
| 97 | + |
| 98 | +<u> |
| 99 | + |
| 100 | +#### Additional properties : [For Development Purpose Only] |
| 101 | + |
| 102 | +</u> |
| 103 | + |
| 104 | +4. `serverVisible` |
| 105 | + |
| 106 | + - Type `Boolean` |
| 107 | + - True will make all plugins visible if set to `true` otherwise `false` won't change anything. |
| 108 | + - This property is accessible for the developers only as it can be only set during development phase. We can see that it is defined in build method of the widget. |
| 109 | + |
| 110 | + ```js |
| 111 | + Widget build(BuildContext context) { |
| 112 | + var serverVisible = false; |
| 113 | + serverVisible = checkFromPluginList(); |
| 114 | + return serverVisible || visible ? child! : Container(); |
| 115 | + } |
| 116 | + ``` |
0 commit comments