Skip to content

Commit

Permalink
#refactor use MyRoute2 for Plugins examples
Browse files Browse the repository at this point in the history
  • Loading branch information
X-Wei committed Jul 27, 2019
1 parent 73868ef commit e79d641
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 82 deletions.
28 changes: 24 additions & 4 deletions lib/my_app_meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,30 @@ const kMyAppRoutesStructure = <MyRouteGroup>[
groupName: 'Plugins',
icon: Icon(Icons.power),
routes: <MyRoute>[
ImagePickerExample(),
WebViewExample(),
MarkdownExample(),
LocalAuthExample(),
MyRoute2(
child: ImagePickerExample(),
sourceFilePath: 'lib/routes/plugins_image_picker_ex.dart',
title: 'Image Picker',
description: 'Pick image from gallery or from camera.',
),
MyRoute2(
child: WebViewExample(),
sourceFilePath: 'lib/routes/plugins_webview_ex.dart',
title: 'Web View',
description: 'Open web page inside Flutter app.',
),
MyRoute2(
child: MarkdownExample(),
sourceFilePath: 'lib/routes/plugins_markdown_ex.dart',
title: 'Markdown rendering',
),
MyRoute2(
child: LocalAuthExample(),
sourceFilePath: 'lib/routes/plugins_local_auth_ex.dart',
title: 'Local auth',
description: 'Authenticate with biometrics(fingerprint).',
links: {},
),
],
),
MyRouteGroup(
Expand Down
27 changes: 4 additions & 23 deletions lib/routes/plugins_image_picker_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,15 @@ import 'dart:io';

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import '../my_route.dart';

class ImagePickerExample extends MyRoute {
const ImagePickerExample(
[String sourceFile = 'lib/routes/plugins_image_picker_ex.dart'])
: super(sourceFile);
class ImagePickerExample extends StatefulWidget {
const ImagePickerExample({Key key}) : super(key: key);

@override
get title => 'Image Picker';

@override
get description => 'Pick image from gallery or from camera.';

@override
Widget buildMyRouteContent(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: _ImagePickerDemo(),
);
}
}

class _ImagePickerDemo extends StatefulWidget {
@override
_ImagePickerDemoState createState() => _ImagePickerDemoState();
_ImagePickerExampleState createState() => _ImagePickerExampleState();
}

class _ImagePickerDemoState extends State<_ImagePickerDemo> {
class _ImagePickerExampleState extends State<ImagePickerExample> {
File _imageFile;

@override
Expand Down
27 changes: 4 additions & 23 deletions lib/routes/plugins_local_auth_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,15 @@ import 'package:flutter/material.dart';
import 'package:local_auth/local_auth.dart';
import 'package:transparent_image/transparent_image.dart'
show kTransparentImage;
import '../my_route.dart';

class LocalAuthExample extends MyRoute {
const LocalAuthExample(
[String sourceFile = 'lib/routes/plugins_local_auth_ex.dart'])
: super(sourceFile);
class LocalAuthExample extends StatefulWidget {
const LocalAuthExample({Key key}) : super(key: key);

@override
get title => 'Local auth';

@override
get description => 'Authenticate with biometrics(fingerprint)';

@override
Widget buildMyRouteContent(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: _LocalAuthDemo(),
);
}
}

class _LocalAuthDemo extends StatefulWidget {
@override
_LocalAuthDemoState createState() => _LocalAuthDemoState();
_LocalAuthExampleState createState() => _LocalAuthExampleState();
}

class _LocalAuthDemoState extends State<_LocalAuthDemo> {
class _LocalAuthExampleState extends State<LocalAuthExample> {
bool _authSuccess = false;
LocalAuthentication _localAuth;

Expand Down
12 changes: 3 additions & 9 deletions lib/routes/plugins_markdown_ex.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:url_launcher/url_launcher.dart';
import '../my_route.dart';

const String _markdownData = '''
# Markdown Example
Expand Down Expand Up @@ -34,16 +33,11 @@ void main() {
Enjoy!
''';

class MarkdownExample extends MyRoute {
const MarkdownExample(
[String sourceFile = 'lib/routes/plugins_markdown_ex.dart'])
: super(sourceFile);
class MarkdownExample extends StatelessWidget {
const MarkdownExample({Key key}) : super(key: key);

@override
get title => 'Markdown rendering';

@override
Widget buildMyRouteContent(BuildContext context) {
Widget build(BuildContext context) {
void _onTapLink(href) async {
if (await canLaunch(href)) {
launch(href);
Expand Down
27 changes: 4 additions & 23 deletions lib/routes/plugins_webview_ex.dart
Original file line number Diff line number Diff line change
@@ -1,34 +1,15 @@
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:url_launcher/url_launcher.dart' as url_launcher;
import '../my_route.dart';

class WebViewExample extends MyRoute {
const WebViewExample(
[String sourceFile = 'lib/routes/plugins_webview_ex.dart'])
: super(sourceFile);
class WebViewExample extends StatefulWidget {
const WebViewExample({Key key}) : super(key: key);

@override
get title => 'Web View';

@override
get description => 'Open web page inside Flutter.';

@override
Widget buildMyRouteContent(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: _WebviewDemo(),
);
}
}

class _WebviewDemo extends StatefulWidget {
@override
_WebviewDemoState createState() => _WebviewDemoState();
_WebViewExampleState createState() => _WebViewExampleState();
}

class _WebviewDemoState extends State<_WebviewDemo> {
class _WebViewExampleState extends State<WebViewExample> {
TextEditingController _controller;

@override
Expand Down

0 comments on commit e79d641

Please sign in to comment.