-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Labels
a: existing-appsIntegration with existing apps via the add-to-app flowIntegration with existing apps via the add-to-app flowengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.
Description
Steps to Reproduce
- follow this document to setup add to app https://github.com/flutter/samples/tree/master/experimental/add_to_app/SimpleIOSExample
- update the main function in this file
experimental/add_to_app/example_module/lib/main.dart
// Copyright 2019 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Module Title',
routes: {
'/': (context) => FullScreenView(),
'/mini': (context) => MiniView(),
},
);
}
}
class FullScreenView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('A Full-screen Flutter View'),
),
body: const MiniView(showExit: true),
);
}
}
class MiniView extends StatefulWidget {
final bool showExit;
const MiniView({this.showExit = false});
@override
_MiniViewState createState() => _MiniViewState();
}
class _MiniViewState extends State<MiniView> with WidgetsBindingObserver {
int count = 0;
AppLifecycleState _lastLifecycleState;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
setState(() {
_lastLifecycleState = state;
});
}
@override
Widget build(BuildContext context) {
final mediaInfo = MediaQuery.of(context);
print('current state $_lastLifecycleState');
return SizedBox.expand(
child: Stack(
children: [
Positioned.fill(
child: DecoratedBox(
decoration: BoxDecoration(
color: Theme.of(context).scaffoldBackgroundColor,
),
),
),
Positioned.fill(
child: Opacity(
opacity: .25,
child: FittedBox(
fit: BoxFit.cover,
child: FlutterLogo(),
),
),
),
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Window is ${mediaInfo.size.width} x '
'${mediaInfo.size.height}.',
style: Theme.of(context).textTheme.headline,
),
SizedBox(height: 16),
Text(
'Taps: $count',
style: Theme.of(context).textTheme.headline,
),
SizedBox(height: 16),
RaisedButton(
onPressed: () => setState(() => count++),
child: Text('Tap me!'),
),
if (widget.showExit) ...[
SizedBox(height: 16),
RaisedButton(
onPressed: () => SystemNavigator.pop(),
child: Text('Exit this screen'),
),
],
],
),
),
],
),
);
}
}
- run the app, and the widget is first build during initialization with lifecyclestate = null which it should be pause.
Metadata
Metadata
Assignees
Labels
a: existing-appsIntegration with existing apps via the add-to-app flowIntegration with existing apps via the add-to-app flowengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.