From 7c3a943548d88f5c1a0d7389bbe3a50a8080e79a Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Tue, 21 Jun 2016 17:28:41 -0700 Subject: [PATCH] Remove the gallery Live Demo buttons, etc (#4678) --- .../lib/demo/grid_list_demo.dart | 7 - .../flutter_gallery/lib/gallery/demo.dart | 211 ++++-------------- .../lib/gallery/syntax_highlighter.dart | 21 +- 3 files changed, 66 insertions(+), 173 deletions(-) diff --git a/examples/flutter_gallery/lib/demo/grid_list_demo.dart b/examples/flutter_gallery/lib/demo/grid_list_demo.dart index e9bdd98c05..758b22177c 100644 --- a/examples/flutter_gallery/lib/demo/grid_list_demo.dart +++ b/examples/flutter_gallery/lib/demo/grid_list_demo.dart @@ -7,10 +7,6 @@ import 'dart:collection'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; -import '../gallery/demo.dart'; - -const String _kExampleCode = 'gridlists'; - enum GridDemoTileStyle { imageOnly, oneLine, @@ -268,9 +264,6 @@ class GridListDemoState extends State { ); }) ) - ), - new DemoBottomBar( - exampleCodeTag: _kExampleCode ) ] ) diff --git a/examples/flutter_gallery/lib/gallery/demo.dart b/examples/flutter_gallery/lib/gallery/demo.dart index cf7d2a878f..f360e1921a 100644 --- a/examples/flutter_gallery/lib/gallery/demo.dart +++ b/examples/flutter_gallery/lib/gallery/demo.dart @@ -8,34 +8,17 @@ import 'package:flutter_markdown/flutter_markdown.dart'; import 'example_code_parser.dart'; import 'syntax_highlighter.dart'; -class SingleComponentDemoData { - SingleComponentDemoData({ +class ComponentDemoTabData { + ComponentDemoTabData({ this.widget, this.exampleCodeTag, this.description, - this.onPressedDemo + this.tabName }); final Widget widget; final String exampleCodeTag; final String description; - final VoidCallback onPressedDemo; -} - -class ComponentDemoTabData extends SingleComponentDemoData { - ComponentDemoTabData({ - Widget widget, - String exampleCodeTag, - String description, - VoidCallback onPressedDemo, - this.tabName - }) : super( - widget: widget, - exampleCodeTag: exampleCodeTag, - description: description, - onPressedDemo: onPressedDemo - ); - final String tabName; static Map buildTabLabels(List demos) { @@ -66,6 +49,16 @@ class TabbedComponentDemoScaffold extends StatelessWidget { final List demos; final String title; + void _showExampleCode(BuildContext context) { + TabBarSelectionState selection = TabBarSelection.of(context); + String tag = selection.value?.exampleCodeTag; + if (tag != null) { + Navigator.push(context, new MaterialPageRoute( + builder: (BuildContext context) => new FullScreenCodeDialog(exampleCodeTag: tag) + )); + } + } + @override Widget build(BuildContext context) { return new TabBarSelection( @@ -73,157 +66,40 @@ class TabbedComponentDemoScaffold extends StatelessWidget { child: new Scaffold( appBar: new AppBar( title: new Text(title), + actions: [ + new Builder( + builder: (BuildContext context) { + return new IconButton( + icon: new Icon(Icons.description), + tooltip: 'Show example code', + onPressed: () { _showExampleCode(context); } + ); + } + ) + ], bottom: new TabBar( isScrollable: true, labels: ComponentDemoTabData.buildTabLabels(demos) ) ), - body: new TabbedComponentDemo(demos) + body: new TabBarView( + children: demos.map((ComponentDemoTabData demo) { + return new Column( + children: [ + new Padding( + padding: const EdgeInsets.all(16.0), + child: new MarkdownBody(data: demo.description) + ), + new Flexible(child: demo.widget) + ] + ); + }).toList() + ) ) ); } } -class TabbedComponentDemo extends StatelessWidget { - TabbedComponentDemo(this.demos); - - final List demos; - - @override - Widget build(BuildContext context) { - return new TabBarView( - children: demos.map(buildTabView).toList() - ); - } - - Widget buildTabView(ComponentDemoTabData demo) { - return new SingleComponentDemo(demo); - } -} - -class SingleComponentDemo extends StatelessWidget { - SingleComponentDemo(this.demo); - - final SingleComponentDemoData demo; - - @override - Widget build(BuildContext context) { - return new Column( - children: [ - new Padding( - padding: new EdgeInsets.all(16.0), - child: new MarkdownBody(data: demo.description) - ), - new Flexible( - child: demo.widget - ), - new DemoBottomBar( - exampleCodeTag: demo.exampleCodeTag, - onPressedDemo: demo.onPressedDemo - ) - ] - ); - } -} - -class DemoBottomBar extends StatelessWidget { - DemoBottomBar({ this.exampleCodeTag, this.onPressedDemo }); - - final String exampleCodeTag; - final VoidCallback onPressedDemo; - - @override - Widget build(BuildContext context) { - VoidCallback onPressedCode; - if (exampleCodeTag != null) { - onPressedCode = () { - Navigator.push(context, new MaterialPageRoute( - builder: (BuildContext context) => new FullScreenCodeDialog(exampleCodeTag: exampleCodeTag) - )); - }; - } - - return new Column( - children: [ - new Divider( - height: 1.0 - ), - new Container( - height: 48.0, - child: new Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - new FlatButton( - child: new Row( - children: [ - new Padding( - padding: new EdgeInsets.only(right: 8.0), - child: new Icon(Icons.code) - ), - new Text('VIEW CODE') - ] - ), - onPressed: onPressedCode - ), - new FlatButton( - child: new Row( - children: [ - new Padding( - padding: new EdgeInsets.only(right: 8.0), - child: new Icon(Icons.star) - ), - new Text('LIVE DEMO') - ] - ), - onPressed: onPressedDemo - ) - ] - ) - ) - ] - ); - } -} - -class FormattedCode extends StatefulWidget { - FormattedCode(this.exampleCode); - - final String exampleCode; - - @override - _FormattedCodeState createState() => new _FormattedCodeState(); -} - -class _FormattedCodeState extends State { - @override - void initState() { - super.initState(); - _formatText(); - } - - TextSpan _formattedText; - - @override - Widget build(BuildContext context) { - return new RichText(text: _formattedText); - } - - @override - void didUpdateConfig(FormattedCode oldConfig) { - super.didUpdateConfig(oldConfig); - - if (oldConfig.exampleCode != config.exampleCode) - _formatText(); - } - - void _formatText() { - _formattedText = new TextSpan( - style: new TextStyle(fontFamily: 'monospace', fontSize: 10.0), - children: [new DartSyntaxHighlighter().format(config.exampleCode)] - ); - } -} - class FullScreenCodeDialog extends StatefulWidget { FullScreenCodeDialog({ this.exampleCodeTag }); @@ -250,6 +126,10 @@ class FullScreenCodeDialogState extends State { @override Widget build(BuildContext context) { + final SyntaxHighlighterStyle style = Theme.of(context).brightness == Brightness.dark + ? SyntaxHighlighterStyle.darkThemeStyle() + : SyntaxHighlighterStyle.lightThemeStyle(); + Widget body; if (_exampleCode == null) { body = new Center( @@ -259,7 +139,14 @@ class FullScreenCodeDialogState extends State { body = new ScrollableViewport( child: new Padding( padding: new EdgeInsets.all(16.0), - child: new FormattedCode(_exampleCode) + child: new RichText( + text: new TextSpan( + style: new TextStyle(fontFamily: 'monospace', fontSize: 10.0), + children: [ + new DartSyntaxHighlighter(style).format(_exampleCode) + ] + ) + ) ) ); } diff --git a/examples/flutter_gallery/lib/gallery/syntax_highlighter.dart b/examples/flutter_gallery/lib/gallery/syntax_highlighter.dart index 4367ece621..973d523a1b 100644 --- a/examples/flutter_gallery/lib/gallery/syntax_highlighter.dart +++ b/examples/flutter_gallery/lib/gallery/syntax_highlighter.dart @@ -17,19 +17,32 @@ class SyntaxHighlighterStyle { this.constantStyle }); - static SyntaxHighlighterStyle defaultStyle() { + static SyntaxHighlighterStyle lightThemeStyle() { return new SyntaxHighlighterStyle( - baseStyle: new TextStyle(color: const Color(0xff000000)), + baseStyle: new TextStyle(color: const Color(0xFF000000)), numberStyle: new TextStyle(color: const Color(0xFF1565C0)), commentStyle: new TextStyle(color: const Color(0xFF9E9E9E)), keywordStyle: new TextStyle(color: const Color(0xFF9C27B0)), stringStyle: new TextStyle(color: const Color(0xFF43A047)), - punctuationStyle: new TextStyle(color: const Color(0xff000000)), + punctuationStyle: new TextStyle(color: const Color(0xFF000000)), classStyle: new TextStyle(color: const Color(0xFF512DA8)), constantStyle: new TextStyle(color: const Color(0xFF795548)) ); } + static SyntaxHighlighterStyle darkThemeStyle() { + return new SyntaxHighlighterStyle( + baseStyle: new TextStyle(color: const Color(0xFFFFFFFF)), + numberStyle: new TextStyle(color: const Color(0xFF1565C0)), + commentStyle: new TextStyle(color: const Color(0xFF9E9E9E)), + keywordStyle: new TextStyle(color: const Color(0xFF80CBC4)), + stringStyle: new TextStyle(color: const Color(0xFF009688)), + punctuationStyle: new TextStyle(color: const Color(0xFFFFFFFF)), + classStyle: new TextStyle(color: const Color(0xFF009688)), + constantStyle: new TextStyle(color: const Color(0xFF795548)) + ); + } + final TextStyle baseStyle; final TextStyle numberStyle; final TextStyle commentStyle; @@ -49,7 +62,7 @@ class DartSyntaxHighlighter extends SyntaxHighlighter { _spans = <_HighlightSpan>[]; if (_style == null) - _style = SyntaxHighlighterStyle.defaultStyle(); + _style = SyntaxHighlighterStyle.darkThemeStyle(); } SyntaxHighlighterStyle _style;