-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/documentation
- Loading branch information
Showing
10 changed files
with
279 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
analyzer: | ||
errors: | ||
always_put_required_named_parameters_first: ignore | ||
include: package:very_good_analysis/analysis_options.yaml | ||
|
||
linter: | ||
rules: | ||
# since this is just an example, there is no need for ubiquitous documentation. | ||
public_member_api_docs: false | ||
public_member_api_docs: false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:auto_route_example/controllers/books/model.dart'; | ||
import 'package:disco/disco.dart'; | ||
|
||
final booksControllerProvider = Provider((context) => BooksController()); | ||
|
||
class BooksController { | ||
final _books = List.generate( | ||
10, | ||
(index) => Book( | ||
id: index, | ||
name: 'Book $index', | ||
description: 'Description for book $index', | ||
), | ||
); | ||
|
||
/// Returns a list of all books. | ||
List<Book> get books { | ||
return _books; | ||
} | ||
|
||
/// Returns a book by its [id]. | ||
Book book(int id) { | ||
return _books.firstWhere((book) => book.id == id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Book { | ||
const Book({ | ||
required this.id, | ||
required this.name, | ||
required this.description, | ||
}); | ||
|
||
final int id; | ||
final String name; | ||
final String description; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:auto_route/annotations.dart'; | ||
import 'package:auto_route_example/controllers/books/controller.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
@RoutePage() | ||
class BookPage extends StatelessWidget { | ||
const BookPage({ | ||
super.key, | ||
@PathParam() required this.bookId, | ||
}); | ||
|
||
final int bookId; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final booksController = booksControllerProvider.of(context); | ||
final book = booksController.book(bookId); | ||
return Scaffold( | ||
appBar: AppBar(title: Text(book.name)), | ||
body: Center( | ||
child: Text(booksController.book(bookId).description), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'package:auto_route/auto_route.dart'; | ||
import 'package:auto_route_example/controllers/books/controller.dart'; | ||
import 'package:auto_route_example/router.dart'; | ||
import 'package:disco/disco.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
@RoutePage() | ||
class BooksWrapperPage extends StatelessWidget implements AutoRouteWrapper { | ||
const BooksWrapperPage({super.key}); | ||
@override | ||
Widget wrappedRoute(BuildContext context) { | ||
return ProviderScope( | ||
providers: [booksControllerProvider], | ||
child: this, | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return const AutoRouter(); | ||
} | ||
} | ||
|
||
@RoutePage() | ||
class BooksPage extends StatelessWidget { | ||
const BooksPage({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final booksController = booksControllerProvider.of(context); | ||
final books = booksController.books; | ||
|
||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Books'), | ||
leading: BackButton( | ||
onPressed: () => const HomeRoute().navigate(context), | ||
), | ||
), | ||
body: ListView.separated( | ||
itemCount: books.length, | ||
itemBuilder: (context, index) { | ||
final book = books[index]; | ||
return ListTile( | ||
title: Text(book.name), | ||
onTap: () => BookRoute(bookId: book.id).navigate(context), | ||
); | ||
}, | ||
separatorBuilder: (context, index) => const SizedBox(height: 8), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:auto_route/auto_route.dart'; | ||
import 'package:auto_route_example/router.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
@RoutePage() | ||
class HomePage extends StatefulWidget { | ||
const HomePage({super.key}); | ||
|
||
@override | ||
State<HomePage> createState() => _HomePageState(); | ||
} | ||
|
||
class _HomePageState extends State<HomePage> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(title: const Text('Home')), | ||
body: Center( | ||
child: ElevatedButton( | ||
child: const Text('Go to books'), | ||
onPressed: () => context.router.root.navigate(const BooksRoute()), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:auto_route/auto_route.dart'; | ||
import 'package:auto_route_example/pages/book.dart'; | ||
import 'package:auto_route_example/pages/books.dart'; | ||
import 'package:auto_route_example/pages/home.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
|
||
part 'router.gr.dart'; | ||
|
||
@AutoRouterConfig() | ||
class AppRouter extends RootStackRouter { | ||
@override | ||
List<AutoRoute> get routes => [ | ||
AutoRoute( | ||
path: '/', | ||
page: HomeRoute.page, | ||
), | ||
AutoRoute( | ||
path: '/books', | ||
page: BooksWrapperRoute.page, | ||
children: [ | ||
AutoRoute(path: '', page: BooksRoute.page, initial: true), | ||
AutoRoute(path: ':bookId', page: BookRoute.page), | ||
], | ||
), | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// dart format width=80 | ||
// GENERATED CODE - DO NOT MODIFY BY HAND | ||
|
||
// ************************************************************************** | ||
// AutoRouterGenerator | ||
// ************************************************************************** | ||
|
||
// ignore_for_file: type=lint | ||
// coverage:ignore-file | ||
|
||
part of 'router.dart'; | ||
|
||
/// generated route for | ||
/// [BookPage] | ||
class BookRoute extends PageRouteInfo<BookRouteArgs> { | ||
BookRoute({Key? key, required int bookId, List<PageRouteInfo>? children}) | ||
: super( | ||
BookRoute.name, | ||
args: BookRouteArgs(key: key, bookId: bookId), | ||
rawPathParams: {'bookId': bookId}, | ||
initialChildren: children, | ||
); | ||
|
||
static const String name = 'BookRoute'; | ||
|
||
static PageInfo page = PageInfo( | ||
name, | ||
builder: (data) { | ||
final pathParams = data.inheritedPathParams; | ||
final args = data.argsAs<BookRouteArgs>( | ||
orElse: () => BookRouteArgs(bookId: pathParams.getInt('bookId')), | ||
); | ||
return BookPage(key: args.key, bookId: args.bookId); | ||
}, | ||
); | ||
} | ||
|
||
class BookRouteArgs { | ||
const BookRouteArgs({this.key, required this.bookId}); | ||
|
||
final Key? key; | ||
|
||
final int bookId; | ||
|
||
@override | ||
String toString() { | ||
return 'BookRouteArgs{key: $key, bookId: $bookId}'; | ||
} | ||
} | ||
|
||
/// generated route for | ||
/// [BooksPage] | ||
class BooksRoute extends PageRouteInfo<void> { | ||
const BooksRoute({List<PageRouteInfo>? children}) | ||
: super(BooksRoute.name, initialChildren: children); | ||
|
||
static const String name = 'BooksRoute'; | ||
|
||
static PageInfo page = PageInfo( | ||
name, | ||
builder: (data) { | ||
return const BooksPage(); | ||
}, | ||
); | ||
} | ||
|
||
/// generated route for | ||
/// [BooksWrapperPage] | ||
class BooksWrapperRoute extends PageRouteInfo<void> { | ||
const BooksWrapperRoute({List<PageRouteInfo>? children}) | ||
: super(BooksWrapperRoute.name, initialChildren: children); | ||
|
||
static const String name = 'BooksWrapperRoute'; | ||
|
||
static PageInfo page = PageInfo( | ||
name, | ||
builder: (data) { | ||
return WrappedRoute(child: const BooksWrapperPage()); | ||
}, | ||
); | ||
} | ||
|
||
/// generated route for | ||
/// [HomePage] | ||
class HomeRoute extends PageRouteInfo<void> { | ||
const HomeRoute({List<PageRouteInfo>? children}) | ||
: super(HomeRoute.name, initialChildren: children); | ||
|
||
static const String name = 'HomeRoute'; | ||
|
||
static PageInfo page = PageInfo( | ||
name, | ||
builder: (data) { | ||
return const HomePage(); | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters