Skip to content

Commit 034e1be

Browse files
committed
update docs for forms, navigation-hub and what-is-nylo
1 parent 64d9f2f commit 034e1be

File tree

3 files changed

+277
-3
lines changed

3 files changed

+277
-3
lines changed

resources/docs/6.x/forms.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@
1515
- [Date and Time Fields](#date-and-time-fields "Date and Time Fields")
1616
- [Password Fields](#password-fields "Password Fields")
1717
- [Masked Input Fields](#masked-input-fields "Masked Input Fields")
18+
- [Checkbox Fields](#checkbox-fields "Checkbox Fields")
19+
- [Picker Fields](#picker-fields "Picker Fields")
20+
- [Radio Fields](#radio-fields "Radio Fields")
21+
- [Chip Fields](#chip-fields "Chip Fields")
22+
- [Switch Box Fields](#switch-box-fields "Switch Box Fields")
1823
- [Form Validation](#form-validation "Form Validation")
1924
- [Form Casts](#form-casts "Form Casts")
2025
- [Managing Form Data](#managing-form-data "Managing Form Data")
26+
- [Submit Button](#submit-button "Submit Button")
2127
- [Form Styling](#form-styling "Form Styling")
2228
- [Advanced Features](#advanced-features "Advanced Features")
2329
- [Form Layout](#form-layout "Form Layout")
@@ -248,6 +254,7 @@ Field("Price", cast: FormCast.currency("usd"))
248254
// Recommended approach
249255
Field.picker("Category", options: ["Electronics", "Clothing", "Books"]),
250256
Field.chips("Tags", options: ["Featured", "Sale", "New"]),
257+
Field.radio("Size", options: ["Small", "Medium", "Large"]),
251258
252259
// Alternative approach
253260
Field("Category",
@@ -319,6 +326,83 @@ Field("Phone",
319326
)
320327
```
321328

329+
<a name="checkbox-fields"></a>
330+
<br>
331+
332+
### Checkbox Fields
333+
334+
```dart
335+
// Recommended approach
336+
Field.checkbox("Accept Terms"),
337+
338+
// Alternative approach
339+
Field("Accept Terms", cast: FormCast.checkbox())
340+
```
341+
342+
<a name="picker-fields"></a>
343+
<br>
344+
345+
### Picker Fields
346+
347+
```dart
348+
// Recommended approach
349+
Field.picker("Category", options: ["Electronics", "Clothing", "Books"]),
350+
351+
// Alternative approach
352+
Field("Category",
353+
cast: FormCast.picker(
354+
options: ["Electronics", "Clothing", "Books"]
355+
)
356+
)
357+
```
358+
359+
<a name="radio-fields"></a>
360+
<br>
361+
362+
### Radio Fields
363+
364+
```dart
365+
// Recommended approach
366+
Field.radio("Size", options: ["Small", "Medium", "Large"]),
367+
368+
// Alternative approach
369+
Field("Size",
370+
cast: FormCast.radio(
371+
options: ["Small", "Medium", "Large"]
372+
)
373+
)
374+
```
375+
376+
<a name="chip-fields"></a>
377+
<br>
378+
379+
### Chip Fields
380+
381+
```dart
382+
// Recommended approach
383+
Field.chips("Tags", options: ["Featured", "Sale", "New"]),
384+
385+
// Alternative approach
386+
Field("Tags",
387+
cast: FormCast.chips(
388+
options: ["Featured", "Sale", "New"]
389+
)
390+
)
391+
```
392+
393+
<a name="switch-box-fields"></a>
394+
<br>
395+
396+
### Switch Box Fields
397+
398+
```dart
399+
// Recommended approach
400+
Field.switchBox("Enable Notifications"),
401+
402+
// Alternative approach
403+
Field("Enable Notifications", cast: FormCast.switchBox())
404+
```
405+
322406
<a name="form-validation"></a>
323407
<br>
324408

@@ -542,6 +626,105 @@ form.clear();
542626
form.clearField("name");
543627
```
544628

629+
<a name="submit-button"></a>
630+
<br>
631+
632+
## Submit Button
633+
634+
In your Form class, you can define a submit button:
635+
636+
```dart
637+
class UserInfoForm extends NyFormData {
638+
UserInfoForm({String? name}) : super(name ?? "user_info");
639+
640+
@override
641+
fields() => [
642+
Field.text("First Name",
643+
style: "compact"
644+
),
645+
Field.text("Last Name",
646+
style: "compact"
647+
),
648+
Field.number("Phone Number",
649+
style: "compact"
650+
),
651+
];
652+
653+
@override
654+
Widget? get submitButton => Button.primary(text: "Submit",
655+
submitForm: (this, (data) {
656+
printInfo(data);
657+
}));
658+
}
659+
```
660+
661+
The `Button` widget is a pre-built component that can be used to submit a form.
662+
All you need to do is pass the `submitForm` parameter to the button.
663+
664+
Out the box, Nylo provides 8 pre-built buttons that you can use to submit a form.
665+
- `Button.primary`
666+
- `Button.secondary`
667+
- `Button.outlined`
668+
- `Button.textOnly`
669+
- `Button.icon`
670+
- `Button.gradient`
671+
- `Button.rounded`
672+
673+
If you want to use a different widget to submit the form, you can call the `submit` method on the form:
674+
675+
```dart
676+
class UserInfoForm extends NyFormData {
677+
UserInfoForm({String? name}) : super(name ?? "user_info");
678+
679+
@override
680+
fields() => [
681+
Field.text("First Name",
682+
style: "compact"
683+
),
684+
Field.text("Last Name",
685+
style: "compact"
686+
),
687+
Field.number("Phone Number",
688+
style: "compact"
689+
),
690+
];
691+
692+
@override
693+
Widget? get submitButton => ElevatedButton(
694+
onPressed: () {
695+
submit(onSuccess: (data) {
696+
printInfo(data);
697+
});
698+
},
699+
child: Text("Submit"),
700+
);
701+
}
702+
```
703+
704+
Lastly, you can also add a submit button directly to the form widget:
705+
706+
```dart
707+
NyForm(
708+
form: form,
709+
footer: Button.primary(text: "Submit", submitForm: (form, (data) {
710+
printInfo(data);
711+
})),
712+
)
713+
```
714+
715+
Or with another widget:
716+
717+
```dart
718+
NyForm(
719+
form: form,
720+
footer: MaterialButton(onPressed: () {
721+
form.submit(onSuccess: (data) {
722+
printInfo(data);
723+
});
724+
}, child: Text("Submit")),
725+
)
726+
```
727+
545728
<a name="form-styling"></a>
546729
<br>
547730

resources/docs/6.x/navigation-hub.md

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
- [Bottom Navigation Bar](#bottom-navigation-bar "Bottom Navigation Bar")
99
- [Top Navigation Bar](#bottom-navigation-bar "Bottom Navigation Bar")
1010
- [Navigating within a tab](#navigating-within-a-tab "Navigating within a tab")
11-
- [Adding Badges to Tabs](#adding-badges-to-tabs "Adding Badges to Tabs")
11+
- [Tabs](#tabs "Tabs")
12+
- [Adding Badges to Tabs](#adding-badges-to-tabs "Adding Badges to Tabs")
13+
- [Adding Alerts to Tabs](#adding-alerts-to-tabs "Adding Alerts to Tabs")
1214
- [Maintaining state](#maintaining-state "Maintaining state")
1315
- [State Actions](#state-actions "State Actions")
1416
- [Loading Style](#loading-style "Loading Style")
@@ -79,7 +81,7 @@ class _BaseNavigationHubState extends NavigationHub<BaseNavigationHub> {
7981
title: "Home",
8082
page: HomeTab(),
8183
icon: Icon(Icons.home),
82-
activeIcon: Icon(Icons.home_filled),
84+
activeIcon: Icon(Icons.home),
8385
),
8486
1: NavigationTab(
8587
title: "Settings",
@@ -231,6 +233,45 @@ _HomeTabState extends State<HomeTab> {
231233
}
232234
```
233235

236+
<a name="tabs"></a>
237+
<br>
238+
239+
## Tabs
240+
241+
Tabs are the main building blocks of a Navigation Hub.
242+
243+
You can add tabs to a Navigation Hub by using the `NavigationTab` class.
244+
245+
``` dart
246+
class _MyNavigationHubState extends NavigationHub<MyNavigationHub> {
247+
...
248+
NavigationHubLayout? layout = NavigationHubLayout.bottomNav();
249+
...
250+
_MyNavigationHubState() : super(() async {
251+
return {
252+
0: NavigationTab(
253+
title: "Home",
254+
page: HomeTab(),
255+
icon: Icon(Icons.home),
256+
activeIcon: Icon(Icons.home),
257+
),
258+
1: NavigationTab(
259+
title: "Settings",
260+
page: SettingsTab(),
261+
icon: Icon(Icons.settings),
262+
activeIcon: Icon(Icons.settings),
263+
),
264+
};
265+
});
266+
```
267+
268+
In the above example, we've added two tabs to the Navigation Hub, Home and Settings.
269+
270+
You can use different kinds of tabs like `NavigationTab`, `NavigationTab.badge`, and `NavigationTab.alert`.
271+
272+
- The `NavigationTab.badge` class is used to add badges to tabs.
273+
- The `NavigationTab.alert` class is used to add alerts to tabs.
274+
- The `NavigationTab` class is used to add a normal tab.
234275

235276
<a name="adding-badges-to-tabs"></a>
236277
<br>
@@ -311,6 +352,55 @@ class _MyNavigationHubState extends NavigationHub<MyNavigationHub> {
311352
});
312353
```
313354

355+
<a name="adding-alerts-to-tabs"></a>
356+
<br>
357+
358+
## Adding Alerts to Tabs
359+
360+
You can add alerts to your tabs.
361+
362+
Sometime you might not want to show a badge count, but you want to show an alert to the user.
363+
364+
To add an alert to a tab, you can use the `NavigationTab.alert` class.
365+
366+
``` dart
367+
class _MyNavigationHubState extends NavigationHub<MyNavigationHub> {
368+
...
369+
NavigationHubLayout? layout = NavigationHubLayout.bottomNav();
370+
...
371+
_MyNavigationHubState() : super(() async {
372+
return {
373+
0: NavigationTab.alert(
374+
title: "Chats",
375+
page: ChatTab(),
376+
icon: Icon(Icons.message),
377+
activeIcon: Icon(Icons.message),
378+
alertColor: Colors.red,
379+
alertEnabled: true,
380+
rememberAlert: false,
381+
),
382+
1: NavigationTab(
383+
title: "Settings",
384+
page: SettingsTab(),
385+
icon: Icon(Icons.settings),
386+
activeIcon: Icon(Icons.settings),
387+
),
388+
};
389+
});
390+
```
391+
392+
This will add an alert to the Chat tab with a red color.
393+
394+
You can also update the alert programmatically.
395+
396+
``` dart
397+
/// Enable the alert
398+
BaseNavigationHub.stateActions.alertEnableTab(tab: 0);
399+
400+
/// Disable the alert
401+
BaseNavigationHub.stateActions.alertDisableTab(tab: 0);
402+
```
403+
314404
<a name="maintaining-state"></a>
315405
<br>
316406

@@ -421,7 +511,7 @@ class _MyNavigationHubState extends NavigationHub<MyNavigationHub> {
421511
title: "Home",
422512
page: HomeTab(),
423513
icon: Icon(Icons.home),
424-
activeIcon: Icon(Icons.home_filled),
514+
activeIcon: Icon(Icons.home),
425515
),
426516
1: NavigationTab(
427517
title: "Settings",

resources/docs/6.x/what-is-nylo.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,4 @@ Here's a shout out to the contributors who have helped build {{ config('app.name
8282
- <a href="https://github.com/stensonb" target="_blank">stensonb</a>
8383
- <a href="https://github.com/ruwiss" target="_blank">ruwiss</a>
8484
- <a href="https://github.com/rytisder" target="_blank">rytisder</a>
85+
- <a href="https://github.com/israelins85" target="_blank">israelins85</a>

0 commit comments

Comments
 (0)