|
|
@ -17,7 +17,7 @@ void main() {
|
|
|
|
runApp(
|
|
|
|
runApp(
|
|
|
|
ChangeNotifierProvider.value(
|
|
|
|
ChangeNotifierProvider.value(
|
|
|
|
value: model,
|
|
|
|
value: model,
|
|
|
|
child: MyApp(),
|
|
|
|
child: const MyApp(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -32,17 +32,17 @@ void main() {
|
|
|
|
class CounterModel extends ChangeNotifier {
|
|
|
|
class CounterModel extends ChangeNotifier {
|
|
|
|
CounterModel() {
|
|
|
|
CounterModel() {
|
|
|
|
_channel.setMethodCallHandler(_handleMessage);
|
|
|
|
_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 _count = 0;
|
|
|
|
|
|
|
|
|
|
|
|
int get count => _count;
|
|
|
|
int get count => _count;
|
|
|
|
|
|
|
|
|
|
|
|
void increment() {
|
|
|
|
void increment() {
|
|
|
|
_channel.invokeMethod('incrementCounter');
|
|
|
|
_channel.invokeMethod<void>('incrementCounter');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<dynamic> _handleMessage(MethodCall call) async {
|
|
|
|
Future<dynamic> _handleMessage(MethodCall call) async {
|
|
|
@ -58,13 +58,15 @@ class CounterModel extends ChangeNotifier {
|
|
|
|
/// It offers two routes, one suitable for displaying as a full screen and
|
|
|
|
/// 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 {
|
|
|
|
/// another designed to be part of a larger UI.class MyApp extends StatelessWidget {
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
|
|
|
|
const MyApp({Key key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
|
|
|
return MaterialApp(
|
|
|
|
title: 'Flutter Module Title',
|
|
|
|
title: 'Flutter Module Title',
|
|
|
|
routes: {
|
|
|
|
routes: {
|
|
|
|
'/': (context) => FullScreenView(),
|
|
|
|
'/': (context) => const FullScreenView(),
|
|
|
|
'/mini': (context) => Contents(),
|
|
|
|
'/mini': (context) => const Contents(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -73,11 +75,13 @@ class MyApp extends StatelessWidget {
|
|
|
|
/// Wraps [Contents] in a Material [Scaffold] so it looks correct when displayed
|
|
|
|
/// Wraps [Contents] in a Material [Scaffold] so it looks correct when displayed
|
|
|
|
/// full-screen.
|
|
|
|
/// full-screen.
|
|
|
|
class FullScreenView extends StatelessWidget {
|
|
|
|
class FullScreenView extends StatelessWidget {
|
|
|
|
|
|
|
|
const FullScreenView({Key key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text('Full-screen Flutter'),
|
|
|
|
title: const Text('Full-screen Flutter'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
body: const Contents(showExit: true),
|
|
|
|
body: const Contents(showExit: true),
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -92,7 +96,7 @@ class FullScreenView extends StatelessWidget {
|
|
|
|
class Contents extends StatelessWidget {
|
|
|
|
class Contents extends StatelessWidget {
|
|
|
|
final bool showExit;
|
|
|
|
final bool showExit;
|
|
|
|
|
|
|
|
|
|
|
|
const Contents({this.showExit = false});
|
|
|
|
const Contents({this.showExit = false, Key key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
@ -108,7 +112,7 @@ class Contents extends StatelessWidget {
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Positioned.fill(
|
|
|
|
const Positioned.fill(
|
|
|
|
child: Opacity(
|
|
|
|
child: Opacity(
|
|
|
|
opacity: .25,
|
|
|
|
opacity: .25,
|
|
|
|
child: FittedBox(
|
|
|
|
child: FittedBox(
|
|
|
@ -126,7 +130,7 @@ class Contents extends StatelessWidget {
|
|
|
|
'${mediaInfo.size.height.toStringAsFixed(1)}',
|
|
|
|
'${mediaInfo.size.height.toStringAsFixed(1)}',
|
|
|
|
style: Theme.of(context).textTheme.headline5,
|
|
|
|
style: Theme.of(context).textTheme.headline5,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(height: 16),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Consumer<CounterModel>(
|
|
|
|
Consumer<CounterModel>(
|
|
|
|
builder: (context, model, child) {
|
|
|
|
builder: (context, model, child) {
|
|
|
|
return Text(
|
|
|
|
return Text(
|
|
|
@ -135,20 +139,20 @@ class Contents extends StatelessWidget {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(height: 16),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Consumer<CounterModel>(
|
|
|
|
Consumer<CounterModel>(
|
|
|
|
builder: (context, model, child) {
|
|
|
|
builder: (context, model, child) {
|
|
|
|
return ElevatedButton(
|
|
|
|
return ElevatedButton(
|
|
|
|
onPressed: () => model.increment(),
|
|
|
|
onPressed: () => model.increment(),
|
|
|
|
child: Text('Tap me!'),
|
|
|
|
child: const Text('Tap me!'),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (showExit) ...[
|
|
|
|
if (showExit) ...[
|
|
|
|
SizedBox(height: 16),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
ElevatedButton(
|
|
|
|
ElevatedButton(
|
|
|
|
onPressed: () => SystemNavigator.pop(animated: true),
|
|
|
|
onPressed: () => SystemNavigator.pop(animated: true),
|
|
|
|
child: Text('Exit this screen'),
|
|
|
|
child: const Text('Exit this screen'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|