mirror of
https://github.com/flutter/samples.git
synced 2025-11-09 06:18:49 +00:00
Adds add2app Flutter module and an iOS project to run it. (#126)
This commit is contained in:
103
experimental/add_to_app/example_module/lib/main.dart
Normal file
103
experimental/add_to_app/example_module/lib/main.dart
Normal file
@@ -0,0 +1,103 @@
|
||||
// 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> {
|
||||
int count = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final mediaInfo = MediaQuery.of(context);
|
||||
|
||||
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'),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user