mirror of
https://github.com/flutter/samples.git
synced 2025-11-09 22:38:42 +00:00
Tidying up add-to-app samples (#160)
This commit is contained in:
@@ -6,7 +6,10 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
/// 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();
|
||||
@@ -19,6 +22,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);
|
||||
@@ -43,6 +53,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 {
|
||||
class MyApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -56,6 +70,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) {
|
||||
@@ -68,6 +84,11 @@ 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 and (optionally) close the Flutter view.
|
||||
class Contents extends StatelessWidget {
|
||||
final bool showExit;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user