mirror of
https://github.com/flutter/samples.git
synced 2026-03-24 13:22:01 +00:00
Tidying up add-to-app samples (#160)
This commit is contained in:
@@ -1 +0,0 @@
|
||||
buildscript {}
|
||||
@@ -7,7 +7,10 @@ import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:url_launcher/url_launcher.dart' as launcher;
|
||||
|
||||
/// The entrypoint for the flutter module.
|
||||
void main() {
|
||||
// This call ensures the Flutter binding has been set up before creating the
|
||||
// MethodChannel-based model.
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
final model = CounterModel();
|
||||
@@ -20,6 +23,13 @@ void main() {
|
||||
);
|
||||
}
|
||||
|
||||
/// A simple model that uses a [MethodChannel] as the source of truth for the
|
||||
/// state of the counter.
|
||||
///
|
||||
/// Rather than storing app state data within the Flutter module itself (where
|
||||
/// the native portions of the app can't access it), this module passes messages
|
||||
/// back to the containing app whenever it needs to increment or retrieve the
|
||||
/// value of the counter.
|
||||
class CounterModel extends ChangeNotifier {
|
||||
CounterModel() {
|
||||
_channel.setMethodCallHandler(_handleMessage);
|
||||
@@ -44,6 +54,10 @@ class CounterModel extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// The "app" displayed by this module.
|
||||
///
|
||||
/// It offers two routes, one suitable for displaying as a full screen and
|
||||
/// another designed to be part of a larger UI.
|
||||
class MyApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -57,6 +71,8 @@ class MyApp extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// Wraps [Contents] in a Material [Scaffold] so it looks correct when displayed
|
||||
/// full-screen.
|
||||
class FullScreenView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -69,6 +85,12 @@ class FullScreenView extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// The actual content displayed by the module.
|
||||
///
|
||||
/// This widget displays info about the state of a counter and how much room (in
|
||||
/// logical pixels) it's been given. It also offers buttons to increment the
|
||||
/// counter, opening the Flutter documentation via the url_launcher plugin, and
|
||||
/// (optionally) close the Flutter view.
|
||||
class Contents extends StatelessWidget {
|
||||
final bool showExit;
|
||||
|
||||
@@ -126,6 +148,8 @@ class Contents extends StatelessWidget {
|
||||
),
|
||||
RaisedButton(
|
||||
onPressed: () async {
|
||||
// Use the url_launcher plugin to open the Flutter docs in
|
||||
// a browser.
|
||||
final url = 'https://flutter.dev/docs';
|
||||
if (await launcher.canLaunch(url)) {
|
||||
launcher.launch(url);
|
||||
|
||||
@@ -115,7 +115,7 @@ packages:
|
||||
name: provider
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.1.0"
|
||||
version: "3.1.0+1"
|
||||
quiver:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -183,7 +183,14 @@ packages:
|
||||
name: url_launcher
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "5.2.0"
|
||||
version: "5.2.5"
|
||||
url_launcher_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -199,5 +206,5 @@ packages:
|
||||
source: hosted
|
||||
version: "3.5.0"
|
||||
sdks:
|
||||
dart: ">=2.5.0 <3.0.0"
|
||||
flutter: ">=1.5.0 <2.0.0"
|
||||
dart: ">=2.6.0-dev <3.0.0"
|
||||
flutter: ">=1.9.1+hotfix.4 <2.0.0"
|
||||
|
||||
@@ -4,13 +4,13 @@ description: An example Flutter module that uses a plugin.
|
||||
version: 1.0.0+1
|
||||
|
||||
environment:
|
||||
sdk: ">=2.5.0 <3.0.0"
|
||||
sdk: ">=2.6.0-dev <3.0.0"
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
provider: ^3.1.0
|
||||
url_launcher: ^5.1.6
|
||||
url_launcher: ^5.2.5
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user