Commit 7c3a9435 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Remove the gallery Live Demo buttons, etc (#4678)

parent a8f6f44a
...@@ -7,10 +7,6 @@ import 'dart:collection'; ...@@ -7,10 +7,6 @@ import 'dart:collection';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import '../gallery/demo.dart';
const String _kExampleCode = 'gridlists';
enum GridDemoTileStyle { enum GridDemoTileStyle {
imageOnly, imageOnly,
oneLine, oneLine,
...@@ -268,9 +264,6 @@ class GridListDemoState extends State<GridListDemo> { ...@@ -268,9 +264,6 @@ class GridListDemoState extends State<GridListDemo> {
); );
}) })
) )
),
new DemoBottomBar(
exampleCodeTag: _kExampleCode
) )
] ]
) )
......
...@@ -8,34 +8,17 @@ import 'package:flutter_markdown/flutter_markdown.dart'; ...@@ -8,34 +8,17 @@ import 'package:flutter_markdown/flutter_markdown.dart';
import 'example_code_parser.dart'; import 'example_code_parser.dart';
import 'syntax_highlighter.dart'; import 'syntax_highlighter.dart';
class SingleComponentDemoData { class ComponentDemoTabData {
SingleComponentDemoData({ ComponentDemoTabData({
this.widget, this.widget,
this.exampleCodeTag, this.exampleCodeTag,
this.description, this.description,
this.onPressedDemo this.tabName
}); });
final Widget widget; final Widget widget;
final String exampleCodeTag; final String exampleCodeTag;
final String description; 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; final String tabName;
static Map<ComponentDemoTabData, TabLabel> buildTabLabels(List<ComponentDemoTabData> demos) { static Map<ComponentDemoTabData, TabLabel> buildTabLabels(List<ComponentDemoTabData> demos) {
...@@ -66,6 +49,16 @@ class TabbedComponentDemoScaffold extends StatelessWidget { ...@@ -66,6 +49,16 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
final List<ComponentDemoTabData> demos; final List<ComponentDemoTabData> demos;
final String title; final String title;
void _showExampleCode(BuildContext context) {
TabBarSelectionState<ComponentDemoTabData> selection = TabBarSelection.of(context);
String tag = selection.value?.exampleCodeTag;
if (tag != null) {
Navigator.push(context, new MaterialPageRoute<FullScreenCodeDialog>(
builder: (BuildContext context) => new FullScreenCodeDialog(exampleCodeTag: tag)
));
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new TabBarSelection<ComponentDemoTabData>( return new TabBarSelection<ComponentDemoTabData>(
...@@ -73,153 +66,36 @@ class TabbedComponentDemoScaffold extends StatelessWidget { ...@@ -73,153 +66,36 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
child: new Scaffold( child: new Scaffold(
appBar: new AppBar( appBar: new AppBar(
title: new Text(title), title: new Text(title),
actions: <Widget>[
new Builder(
builder: (BuildContext context) {
return new IconButton(
icon: new Icon(Icons.description),
tooltip: 'Show example code',
onPressed: () { _showExampleCode(context); }
);
}
)
],
bottom: new TabBar<ComponentDemoTabData>( bottom: new TabBar<ComponentDemoTabData>(
isScrollable: true, isScrollable: true,
labels: ComponentDemoTabData.buildTabLabels(demos) labels: ComponentDemoTabData.buildTabLabels(demos)
) )
), ),
body: new TabbedComponentDemo(demos) body: new TabBarView<ComponentDemoTabData>(
) children: demos.map((ComponentDemoTabData demo) {
); return new Column(
} children: <Widget>[
} new Padding(
padding: const EdgeInsets.all(16.0),
class TabbedComponentDemo extends StatelessWidget { child: new MarkdownBody(data: demo.description)
TabbedComponentDemo(this.demos);
final List<ComponentDemoTabData> demos;
@override
Widget build(BuildContext context) {
return new TabBarView<ComponentDemoTabData>(
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: <Widget>[
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<FullScreenCodeDialog>(
builder: (BuildContext context) => new FullScreenCodeDialog(exampleCodeTag: exampleCodeTag)
));
};
}
return new Column(
children: <Widget>[
new Divider(
height: 1.0
),
new Container(
height: 48.0,
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new FlatButton(
child: new Row(
children: <Widget>[
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: <Widget>[
new Padding(
padding: new EdgeInsets.only(right: 8.0),
child: new Icon(Icons.star)
),
new Text('LIVE DEMO')
]
), ),
onPressed: onPressedDemo new Flexible(child: demo.widget)
) ]
] );
) }).toList()
) )
] )
);
}
}
class FormattedCode extends StatefulWidget {
FormattedCode(this.exampleCode);
final String exampleCode;
@override
_FormattedCodeState createState() => new _FormattedCodeState();
}
class _FormattedCodeState extends State<FormattedCode> {
@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: <TextSpan>[new DartSyntaxHighlighter().format(config.exampleCode)]
); );
} }
} }
...@@ -250,6 +126,10 @@ class FullScreenCodeDialogState extends State<FullScreenCodeDialog> { ...@@ -250,6 +126,10 @@ class FullScreenCodeDialogState extends State<FullScreenCodeDialog> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final SyntaxHighlighterStyle style = Theme.of(context).brightness == Brightness.dark
? SyntaxHighlighterStyle.darkThemeStyle()
: SyntaxHighlighterStyle.lightThemeStyle();
Widget body; Widget body;
if (_exampleCode == null) { if (_exampleCode == null) {
body = new Center( body = new Center(
...@@ -259,7 +139,14 @@ class FullScreenCodeDialogState extends State<FullScreenCodeDialog> { ...@@ -259,7 +139,14 @@ class FullScreenCodeDialogState extends State<FullScreenCodeDialog> {
body = new ScrollableViewport( body = new ScrollableViewport(
child: new Padding( child: new Padding(
padding: new EdgeInsets.all(16.0), 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: <TextSpan>[
new DartSyntaxHighlighter(style).format(_exampleCode)
]
)
)
) )
); );
} }
......
...@@ -17,19 +17,32 @@ class SyntaxHighlighterStyle { ...@@ -17,19 +17,32 @@ class SyntaxHighlighterStyle {
this.constantStyle this.constantStyle
}); });
static SyntaxHighlighterStyle defaultStyle() { static SyntaxHighlighterStyle lightThemeStyle() {
return new SyntaxHighlighterStyle( return new SyntaxHighlighterStyle(
baseStyle: new TextStyle(color: const Color(0xff000000)), baseStyle: new TextStyle(color: const Color(0xFF000000)),
numberStyle: new TextStyle(color: const Color(0xFF1565C0)), numberStyle: new TextStyle(color: const Color(0xFF1565C0)),
commentStyle: new TextStyle(color: const Color(0xFF9E9E9E)), commentStyle: new TextStyle(color: const Color(0xFF9E9E9E)),
keywordStyle: new TextStyle(color: const Color(0xFF9C27B0)), keywordStyle: new TextStyle(color: const Color(0xFF9C27B0)),
stringStyle: new TextStyle(color: const Color(0xFF43A047)), 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)), classStyle: new TextStyle(color: const Color(0xFF512DA8)),
constantStyle: new TextStyle(color: const Color(0xFF795548)) 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 baseStyle;
final TextStyle numberStyle; final TextStyle numberStyle;
final TextStyle commentStyle; final TextStyle commentStyle;
...@@ -49,7 +62,7 @@ class DartSyntaxHighlighter extends SyntaxHighlighter { ...@@ -49,7 +62,7 @@ class DartSyntaxHighlighter extends SyntaxHighlighter {
_spans = <_HighlightSpan>[]; _spans = <_HighlightSpan>[];
if (_style == null) if (_style == null)
_style = SyntaxHighlighterStyle.defaultStyle(); _style = SyntaxHighlighterStyle.darkThemeStyle();
} }
SyntaxHighlighterStyle _style; SyntaxHighlighterStyle _style;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment