Skip to content

Commit

Permalink
#refactor Add MyRoute2 class
Browse files Browse the repository at this point in the history
So that each example don't need to extend from MyRoute, and instead we can
define MyRotue2 objects in my_app_meta.dart
Following this there will have a BIG refactoring to
move the title/description/links inside my_app_meta
  • Loading branch information
X-Wei committed Jul 27, 2019
1 parent 7047dd2 commit 6bce619
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions lib/my_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class MyRoute extends StatelessWidget {

// Returns a set of links {title:link} that are relative to the route. Can put
// documention links or reference video/article links here.
Map<String, String> get links => {};
Map<String, String> get links => null;

// Returns the widget that will be shown in the "Preview" tab.
Widget buildMyRouteContent(BuildContext context);
Expand Down Expand Up @@ -73,7 +73,7 @@ abstract class MyRoute extends StatelessWidget {
return <Widget>[
if (this.routeName != Navigator.defaultRouteName)
settings.starStatusOfRoute(this.routeName),
if (this.links.isNotEmpty)
if (this.links?.isNotEmpty ?? false)
PopupMenuButton(
itemBuilder: (context) {
return <PopupMenuItem>[
Expand All @@ -95,3 +95,31 @@ abstract class MyRoute extends StatelessWidget {
];
}
}

class MyRoute2 extends MyRoute {
final String sourceFilePath;
final Widget child;
final String _title;
final String description;
final Map<String, String> links;

const MyRoute2(
{@required this.sourceFilePath,
@required this.child,
String title,
this.description,
this.links})
: _title = title,
super(sourceFilePath);

@override
String get routeName => '/${this.child.runtimeType.toString()}';

@override
String get title => _title ?? this.routeName;

@override
Widget buildMyRouteContent(BuildContext context) {
return this.child;
}
}

0 comments on commit 6bce619

Please sign in to comment.