Skip to content

Commit

Permalink
Update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Lopes authored and Michael Lopes committed Feb 21, 2024
1 parent f79402d commit b07c1f0
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 25 deletions.
164 changes: 139 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,156 @@
[![Build](https://github.com/michaelopes/simple_navigator/actions/workflows/build.yaml/badge.svg)](https://github.com/michaelopes/simple_navigator/actions/workflows/build.yaml) [![codecov](https://codecov.io/gh/michaelopes/simple_navigator/graph/badge.svg?token=7AS82WFNNW)](https://codecov.io/gh/michaelopes/simple_navigator)
[![pub](https://img.shields.io/pub/v/simple_navigator.svg?color=success)](https://pub.dev/packages/simple_navigator)

<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
# SimpleNavigator - Flutter Package for Easy Named Route Navigation

For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
SimpleNavigator is a lightweight Flutter package designed to simplify named route navigation within your Flutter application. With a focus on simplicity and ease of use, SimpleNavigator provides an alternative to more complex navigation solutions like go_router.

For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->
## Features
- **Easy-to-Use API:** Simplify your navigation code with a straightforward API.
- **Tabbed Navigation:** Seamlessly integrate tab-based navigation with SimpleNavigatorTabRoute.
- **Route Guards:** Add route guards to delay navigation or perform asynchronous tasks before navigating.
- **URL Strategy:** Enable URL strategy for cleaner and more user-friendly URLs.

TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
## Getting Started
To get started with SimpleNavigator, follow these simple steps:

## Features
1. **Install the Package:**
Add the following dependency to your `pubspec.yaml` file:

TODO: List what your package can do. Maybe include images, gifs, or videos. docs1
```yaml
dependencies:
simple_navigator: ^1.0.0
```

## Getting started
2. **Import the Package:**
Import the package in your Dart file:

TODO: List prerequisites and provide or point to information on how to
start using the package.
```dart
import 'package:simple_navigator/simple_navigator.dart';
```

## Usage
3. **Set Up Routes:**
In your `main.dart` file, configure your routes using `SN.setRoutes`:

```dart
void main() {
SN.setRoutes(
// Add your routes configuration here
);
runApp(const MyApp());
}
```

4. **Implement MaterialApp:**
Use the `MaterialApp.router` widget in your `MyApp` class:

TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.

```dart
const like = 'sample';
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp.router(
theme: Theme.of(context).copyWith(
scaffoldBackgroundColor: Colors.amber,
),
routerDelegate: SN.delegate,
routeInformationParser: SN.parser,
);
}
}
```

## Additional information
## Example Routes Configuration
Here's an example of how you can set up routes using SimpleNavigator:

```dart
bool isUserLogged = false
SN.setRoutes(
urlStrategy: true,
// Here, the reference to the splash page is added.
// Its behavior will be explained in a dedicated topic.
splash: (_) => SplashPage(),
observers: [
TestObs(),
],
routes: [
//Here, a root route with support for tabs is created.
SimpleNavigatorTabRoute(
path: "/",
builder: (_, child) => HomePage(
child: child,
),
tabs: ["/main", "/settings", "/profile"],
guard: (path) async {
await Future.delayed(const Duration(milliseconds: 2000));
return path;
},
),
//Here, a non-root route with support for tabs is created.
SimpleNavigatorTabRoute(
path: "/tabs",
builder: (_, child) => TabsPage(
child: child,
),
tabs: ["/main", "/settings", "/profile"],
guard: (path) async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
isUserLogged = prefs.getString('user-logged') != null;
return isUserLogged ? path : "/login";
},
),
//Add a simple route
SimpleNavigatorRoute(
path: "/login",
builder: (_) => const LoginPage(),
),
//Here, a simple route with a guard is added. What is the guard?
//The guard is a feature that is executed before finalizing a route and can be
//used for security checks, as in the example below. However, any other
//type of execution can be performed within the guard.
//The route will only be finalized after all checks have been successfully processed.
SimpleNavigatorRoute(
path: "/feed",
builder: (_) => const FeedPage(),
guard: (path) async {
return isUserLogged ? path : "/login";
},
//Loading to be displayed while the guard is not processed.
//If not informed, it will show the default loading of SimpleNavigator.
guardLoadingBuilder: (context) => const Center(child: CircularProgressIndicator(),),
),
SimpleNavigatorRoute(
path: "/main",
builder: (_) => const MainPage(),
guard: (path) async {
return isUserLogged ? path : "/login";
},
),
SimpleNavigatorRoute(
path: "/settings",
builder: (_) => const SettingsPage(),
guard: (path) async {
return isUserLogged ? path : "/login";
},
),
SimpleNavigatorRoute(
path: "/profile",
builder: (_) => const ProfilePage(),
guard: (path) async {
return isUserLogged ? path : "/login";
},
),
//Here, a route is added with path parameter passing, for example: :number.
SimpleNavigatorRoute(
path: "/sub/:number",
builder: (_) => const SubPage(),
guard: (path) async {
return isUserLogged ? path : "/login";
},
)
],
);
```

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
File renamed without changes.

0 comments on commit b07c1f0

Please sign in to comment.