Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Added Navigation Rail demo to Material section #342

Merged
merged 12 commits into from
Oct 13, 2020
452 changes: 452 additions & 0 deletions lib/codeviewer/code_segments.dart

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions lib/data/demos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import 'package:gallery/demos/material/grid_list_demo.dart';
import 'package:gallery/demos/material/list_demo.dart';
import 'package:gallery/demos/material/menu_demo.dart';
import 'package:gallery/demos/material/navigation_drawer.dart';
import 'package:gallery/demos/material/navigation_rail_demo.dart';
import 'package:gallery/demos/material/picker_demo.dart';
import 'package:gallery/demos/material/progress_indicator_demo.dart';
import 'package:gallery/demos/material/selection_controls_demo.dart';
Expand Down Expand Up @@ -538,6 +539,22 @@ List<GalleryDemo> materialDemos(GalleryLocalizations localizations) {
],
category: GalleryDemoCategory.material,
),
GalleryDemo(
title: localizations.demoNavigationRailTitle,
icon: GalleryIcons.navigationRail,
slug: 'nav_rail',
subtitle: localizations.demoNavigationRailSubtitle,
configurations: [
GalleryDemoConfiguration(
title: localizations.demoNavigationRailTitle,
description: localizations.demoNavigationRailDescription,
documentationUrl: '$_docsBaseUrl/material/NavigationRail-class.html',
buildRoute: (_) => const NavRailDemo(),
code: CodeSegments.navRailDemo,
),
],
category: GalleryDemoCategory.material,
),
GalleryDemo(
title: localizations.demoPickersTitle,
icon: GalleryIcons.event,
Expand Down
4 changes: 4 additions & 0 deletions lib/data/icons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,8 @@ class GalleryIcons {
0xe927,
fontFamily: 'GalleryIcons',
);
static const IconData navigationRail = IconData(
60080,
fontFamily: 'MaterialIcons',
rami-a marked this conversation as resolved.
Show resolved Hide resolved
);
}
101 changes: 101 additions & 0 deletions lib/demos/material/navigation_rail_demo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright 2019 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/gallery_localizations.dart';

// BEGIN navRailDemo

class NavRailDemo extends StatefulWidget {
const NavRailDemo({Key key}) : super(key: key);

@override
_NavRailDemoState createState() => _NavRailDemoState();
}

class _NavRailDemoState extends State<NavRailDemo> {
int _selectedIndex = 0;

@override
Widget build(BuildContext context) {
final localization = GalleryLocalizations.of(context);
final destinationFirst = localization.demoNavigationRailFirst;
final destinationSecond = localization.demoNavigationRailSecond;
final destinationThird = localization.demoNavigationRailThird;
final selectedItem = <String>[
rami-a marked this conversation as resolved.
Show resolved Hide resolved
destinationFirst,
destinationSecond,
destinationThird
];
return Scaffold(
appBar: AppBar(
title: Text(
localization.demoNavigationRailTitle,
),
),
body: Row(
children: [
NavigationRail(
leading: FloatingActionButton(
child: const Icon(Icons.add),
onPressed: () {},
),
selectedIndex: _selectedIndex,
clocksmith marked this conversation as resolved.
Show resolved Hide resolved
onDestinationSelected: (index) {
setState(() {
_selectedIndex = index;
});
},
labelType: NavigationRailLabelType.selected,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good choice for this demo!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

destinations: [
NavigationRailDestination(
icon: const Icon(
Icons.favorite_border,
),
selectedIcon: const Icon(
Icons.favorite,
),
label: Text(
destinationFirst,
),
),
NavigationRailDestination(
icon: const Icon(
Icons.bookmark_border,
),
selectedIcon: const Icon(
Icons.book,
),
label: Text(
destinationSecond,
),
),
NavigationRailDestination(
icon: const Icon(
Icons.star_border,
),
selectedIcon: const Icon(
Icons.star,
),
label: Text(
destinationThird,
),
),
],
),
const VerticalDivider(thickness: 1, width: 1),
Expanded(
child: Center(
child: Text(
selectedItem[_selectedIndex],
),
),
),
],
),
);
}
}

// END
24 changes: 24 additions & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,30 @@
"@demoNavigationDrawerText": {
"description": "Description to open navigation drawer."
},
"demoNavigationRailTitle": "Navigation Rail",
"@demoNavigationRailTitle": {
"description": "Title for the material Navigation Rail component demo."
},
"demoNavigationRailSubtitle": "Displaying a Navigation Rail within an app",
"@demoNavigationRailSubtitle": {
"description": "Subtitle for the material Navigation Rail component demo."
},
"demoNavigationRailDescription": "A material widget that is meant to be displayed at the left or right of an app to navigate between a small number of views, typically between three and five.",
"@demoNavigationRailDescription": {
"description": "Description for the material Navigation Rail component demo."
},
"demoNavigationRailFirst": "First",
"@demoNavigationRailFirst": {
"description": "Navigation Rail destination first label."
},
"demoNavigationRailSecond": "Second",
"@demoNavigationRailSecond": {
"description": "Navigation Rail destination second label."
},
"demoNavigationRailThird": "Third",
"@demoNavigationRailThird": {
"description": "Navigation Rail destination Third label."
},
"demoMenuAnItemWithASimpleMenu": "An item with a simple menu",
"@demoMenuAnItemWithASimpleMenu": {
"description": "Label next to a button that opens a simple menu. A menu displays a list of choices on a temporary surface. Used as an example in a demo."
Expand Down
24 changes: 24 additions & 0 deletions lib/l10n/intl_en_US.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,30 @@
name="demoNavigationDrawerText"
description="Description to open navigation drawer."
>Swipe from the edge or tap the upper-left icon to see the drawer</string>
<string
name="demoNavigationRailTitle"
description="Title for the material Navigation Rail component demo."
>Navigation Rail</string>
<string
name="demoNavigationRailSubtitle"
description="Subtitle for the material Navigation Rail component demo."
>Displaying a Navigation Rail within an app</string>
<string
name="demoNavigationRailDescription"
description="Description for the material Navigation Rail component demo."
>A material widget that is meant to be displayed at the left or right of an app to navigate between a small number of views, typically between three and five.</string>
<string
name="demoNavigationRailFirst"
description="Navigation Rail destination first label."
>First</string>
<string
name="demoNavigationRailSecond"
description="Navigation Rail destination second label."
>Second</string>
<string
name="demoNavigationRailThird"
description="Navigation Rail destination Third label."
>Third</string>
<string
name="demoMenuAnItemWithASimpleMenu"
description="Label next to a button that opens a simple menu. A menu displays a list of choices on a temporary surface. Used as an example in a demo."
Expand Down