|
|
|
@ -20,7 +20,7 @@ void main() {
|
|
|
|
|
runApp(
|
|
|
|
|
ChangeNotifierProvider.value(
|
|
|
|
|
value: model,
|
|
|
|
|
child: MyApp(),
|
|
|
|
|
child: const MyApp(),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
@ -30,7 +30,7 @@ void main() {
|
|
|
|
|
// This is unfortunately in this file due to
|
|
|
|
|
// https://github.com/flutter/flutter/issues/72630.
|
|
|
|
|
void showCell() {
|
|
|
|
|
runApp(Cell());
|
|
|
|
|
runApp(const Cell());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A simple model that uses a [MethodChannel] as the source of truth for the
|
|
|
|
@ -43,17 +43,17 @@ void showCell() {
|
|
|
|
|
class CounterModel extends ChangeNotifier {
|
|
|
|
|
CounterModel() {
|
|
|
|
|
_channel.setMethodCallHandler(_handleMessage);
|
|
|
|
|
_channel.invokeMethod('requestCounter');
|
|
|
|
|
_channel.invokeMethod<void>('requestCounter');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final _channel = MethodChannel('dev.flutter.example/counter');
|
|
|
|
|
final _channel = const MethodChannel('dev.flutter.example/counter');
|
|
|
|
|
|
|
|
|
|
int _count = 0;
|
|
|
|
|
|
|
|
|
|
int get count => _count;
|
|
|
|
|
|
|
|
|
|
void increment() {
|
|
|
|
|
_channel.invokeMethod('incrementCounter');
|
|
|
|
|
_channel.invokeMethod<void>('incrementCounter');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<dynamic> _handleMessage(MethodCall call) async {
|
|
|
|
@ -69,13 +69,15 @@ class CounterModel extends ChangeNotifier {
|
|
|
|
|
/// 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 {
|
|
|
|
|
const MyApp({Key key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return MaterialApp(
|
|
|
|
|
title: 'Flutter Module Title',
|
|
|
|
|
routes: {
|
|
|
|
|
'/': (context) => FullScreenView(),
|
|
|
|
|
'/mini': (context) => Contents(),
|
|
|
|
|
'/': (context) => const FullScreenView(),
|
|
|
|
|
'/mini': (context) => const Contents(),
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
@ -84,11 +86,13 @@ class MyApp extends StatelessWidget {
|
|
|
|
|
/// Wraps [Contents] in a Material [Scaffold] so it looks correct when displayed
|
|
|
|
|
/// full-screen.
|
|
|
|
|
class FullScreenView extends StatelessWidget {
|
|
|
|
|
const FullScreenView({Key key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
title: Text('Full-screen Flutter with plugin'),
|
|
|
|
|
title: const Text('Full-screen Flutter with plugin'),
|
|
|
|
|
),
|
|
|
|
|
body: const Contents(showExit: true),
|
|
|
|
|
);
|
|
|
|
@ -104,7 +108,7 @@ class FullScreenView extends StatelessWidget {
|
|
|
|
|
class Contents extends StatelessWidget {
|
|
|
|
|
final bool showExit;
|
|
|
|
|
|
|
|
|
|
const Contents({this.showExit = false});
|
|
|
|
|
const Contents({this.showExit = false, Key key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
@ -120,7 +124,7 @@ class Contents extends StatelessWidget {
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Positioned.fill(
|
|
|
|
|
const Positioned.fill(
|
|
|
|
|
child: Opacity(
|
|
|
|
|
opacity: .25,
|
|
|
|
|
child: FittedBox(
|
|
|
|
@ -138,7 +142,7 @@ class Contents extends StatelessWidget {
|
|
|
|
|
'${mediaInfo.size.height.toStringAsFixed(1)}',
|
|
|
|
|
style: Theme.of(context).textTheme.headline5,
|
|
|
|
|
),
|
|
|
|
|
SizedBox(height: 16),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
Consumer<CounterModel>(
|
|
|
|
|
builder: (context, model, child) {
|
|
|
|
|
return Text(
|
|
|
|
@ -147,12 +151,12 @@ class Contents extends StatelessWidget {
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
SizedBox(height: 16),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
Consumer<CounterModel>(
|
|
|
|
|
builder: (context, model, child) {
|
|
|
|
|
return ElevatedButton(
|
|
|
|
|
onPressed: () => model.increment(),
|
|
|
|
|
child: Text('Tap me!'),
|
|
|
|
|
child: const Text('Tap me!'),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
@ -160,18 +164,18 @@ class Contents extends StatelessWidget {
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
// Use the url_launcher plugin to open the Flutter docs in
|
|
|
|
|
// a browser.
|
|
|
|
|
final url = 'https://flutter.dev/docs';
|
|
|
|
|
const url = 'https://flutter.dev/docs';
|
|
|
|
|
if (await launcher.canLaunch(url)) {
|
|
|
|
|
launcher.launch(url);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
child: Text('Open Flutter Docs'),
|
|
|
|
|
child: const Text('Open Flutter Docs'),
|
|
|
|
|
),
|
|
|
|
|
if (showExit) ...[
|
|
|
|
|
SizedBox(height: 16),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: () => SystemNavigator.pop(),
|
|
|
|
|
child: Text('Exit this screen'),
|
|
|
|
|
child: const Text('Exit this screen'),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|