From e79d6417ca91a90d5d08350241e0e1254a61e75c Mon Sep 17 00:00:00 2001 From: x-wei Date: Sat, 27 Jul 2019 23:56:51 +0200 Subject: [PATCH] #refactor use MyRoute2 for Plugins examples --- lib/my_app_meta.dart | 28 +++++++++++++++++++++---- lib/routes/plugins_image_picker_ex.dart | 27 ++++-------------------- lib/routes/plugins_local_auth_ex.dart | 27 ++++-------------------- lib/routes/plugins_markdown_ex.dart | 12 +++-------- lib/routes/plugins_webview_ex.dart | 27 ++++-------------------- 5 files changed, 39 insertions(+), 82 deletions(-) diff --git a/lib/my_app_meta.dart b/lib/my_app_meta.dart index d14abe9e..5d537214 100644 --- a/lib/my_app_meta.dart +++ b/lib/my_app_meta.dart @@ -598,10 +598,30 @@ const kMyAppRoutesStructure = [ groupName: 'Plugins', icon: Icon(Icons.power), routes: [ - 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( diff --git a/lib/routes/plugins_image_picker_ex.dart b/lib/routes/plugins_image_picker_ex.dart index 251548b2..bec8f332 100644 --- a/lib/routes/plugins_image_picker_ex.dart +++ b/lib/routes/plugins_image_picker_ex.dart @@ -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 { File _imageFile; @override diff --git a/lib/routes/plugins_local_auth_ex.dart b/lib/routes/plugins_local_auth_ex.dart index 2385d81d..fc93e9cd 100644 --- a/lib/routes/plugins_local_auth_ex.dart +++ b/lib/routes/plugins_local_auth_ex.dart @@ -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 { bool _authSuccess = false; LocalAuthentication _localAuth; diff --git a/lib/routes/plugins_markdown_ex.dart b/lib/routes/plugins_markdown_ex.dart index 410515e4..ec5c7d3f 100644 --- a/lib/routes/plugins_markdown_ex.dart +++ b/lib/routes/plugins_markdown_ex.dart @@ -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 @@ -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); diff --git a/lib/routes/plugins_webview_ex.dart b/lib/routes/plugins_webview_ex.dart index ccc89c9f..993b94a2 100644 --- a/lib/routes/plugins_webview_ex.dart +++ b/lib/routes/plugins_webview_ex.dart @@ -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 { TextEditingController _controller; @override