Skip to content

Commit 55e4f9c

Browse files
Renzo-OlivaresRenzo Olivares
andauthored
Refactor flutter_view example to not use material (flutter#190377)
This PR refactors the `flutter_view` example to not use `material`. It also migrates the iOS app to utilize the UIScene lifecycle. Without the migration the app refused to run, and showed the error below. ``` failure in void _UIApplicationEvaluateRuntimeIssueForNoSceneLifecycleAdoption(void)_block_invoke (UIApplication_RuntimeIssues.m:106) : Application failed to launch: UIScene life cycle is required for apps built with this SDK. See "Transitioning to the UIKit scene-based life cycle" in the UIKit documentation for more information on migration. ``` ## Android: https://github.com/user-attachments/assets/6b137881-2fbc-4756-8846-d57ec978e9c1 ## iOS: https://github.com/user-attachments/assets/abde493c-2b24-4f3e-8e91-e19f80fc9e56 Part of flutter#190305 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Renzo Olivares <[email protected]>
1 parent eed6f4b commit 55e4f9c

8 files changed

Lines changed: 147 additions & 24 deletions

File tree

‎dev/bots/check_examples_cross_imports.dart‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,6 @@ class ExamplesCrossImportChecker {
585585
'packages/flutter/examples/api/test/widgets/scrollbar/raw_scrollbar.1_test.dart',
586586
'packages/flutter/examples/api/test/widgets/inherited_notifier/inherited_notifier.0_test.dart',
587587
'packages/flutter/examples/api/test/widgets/text_magnifier/text_magnifier.0_test.dart',
588-
'examples/flutter_view/lib/main.dart',
589588
'examples/texture/lib/main.dart',
590589
};
591590

‎examples/flutter_view/ios/Runner.xcodeproj/project.pbxproj‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
2DE332E71E55C6D800393FD5 /* MainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DE332E61E55C6D800393FD5 /* MainViewController.m */; };
1313
3B3967051E83383D004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967041E83383D004F5970 /* AppFrameworkInfo.plist */; };
1414
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
15+
A1B2C3D4E5F6000100000001 /* SceneDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C3D4E5F6000100000003 /* SceneDelegate.m */; };
1516
97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; };
1617
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
1718
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
@@ -41,6 +42,8 @@
4142
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
4243
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
4344
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
45+
A1B2C3D4E5F6000100000002 /* SceneDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SceneDelegate.h; sourceTree = "<group>"; };
46+
A1B2C3D4E5F6000100000003 /* SceneDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SceneDelegate.m; sourceTree = "<group>"; };
4447
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
4548
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
4649
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -96,6 +99,8 @@
9699
2DD8945E1E5B87AF0010574F /* ic_add.png */,
97100
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */,
98101
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */,
102+
A1B2C3D4E5F6000100000002 /* SceneDelegate.h */,
103+
A1B2C3D4E5F6000100000003 /* SceneDelegate.m */,
99104
2DE332E81E55C6F100393FD5 /* MainViewController.h */,
100105
2DE332E61E55C6D800393FD5 /* MainViewController.m */,
101106
2D4B11261E55A15A00FF14DB /* NativeViewController.m */,
@@ -228,6 +233,7 @@
228233
buildActionMask = 2147483647;
229234
files = (
230235
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */,
236+
A1B2C3D4E5F6000100000001 /* SceneDelegate.m in Sources */,
231237
97C146F31CF9000F007C117D /* main.m in Sources */,
232238
2D4B11271E55A15A00FF14DB /* NativeViewController.m in Sources */,
233239
2DE332E71E55C6D800393FD5 /* MainViewController.m in Sources */,

‎examples/flutter_view/ios/Runner/AppDelegate.m‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
1212
return YES;
1313
}
1414

15+
#pragma mark - UISceneSession lifecycle
16+
17+
- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
18+
return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
19+
}
20+
21+
- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
22+
}
23+
1524
@end

‎examples/flutter_view/ios/Runner/Info.plist‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,24 @@
4343
<true/>
4444
<key>UIApplicationSupportsIndirectInputEvents</key>
4545
<true/>
46+
<key>UIApplicationSceneManifest</key>
47+
<dict>
48+
<key>UIApplicationSupportsMultipleScenes</key>
49+
<false/>
50+
<key>UISceneConfigurations</key>
51+
<dict>
52+
<key>UIWindowSceneSessionRoleApplication</key>
53+
<array>
54+
<dict>
55+
<key>UISceneConfigurationName</key>
56+
<string>Default Configuration</string>
57+
<key>UISceneDelegateClassName</key>
58+
<string>SceneDelegate</string>
59+
<key>UISceneStoryboardFile</key>
60+
<string>Main</string>
61+
</dict>
62+
</array>
63+
</dict>
64+
</dict>
4665
</dict>
4766
</plist>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#import <UIKit/UIKit.h>
6+
7+
@interface SceneDelegate : UIResponder <UIWindowSceneDelegate>
8+
9+
@property (strong, nonatomic) UIWindow * window;
10+
11+
@end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#import "SceneDelegate.h"
6+
7+
@implementation SceneDelegate
8+
9+
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
10+
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
11+
}
12+
13+
- (void)sceneDidDisconnect:(UIScene *)scene {
14+
}
15+
16+
- (void)sceneDidBecomeActive:(UIScene *)scene {
17+
}
18+
19+
- (void)sceneWillResignActive:(UIScene *)scene {
20+
}
21+
22+
- (void)sceneWillEnterForeground:(UIScene *)scene {
23+
}
24+
25+
- (void)sceneDidEnterBackground:(UIScene *)scene {
26+
}
27+
28+
@end

‎examples/flutter_view/lib/main.dart‎

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
// found in the LICENSE file.
44

55
import 'dart:async';
6-
import 'package:flutter/material.dart';
6+
77
import 'package:flutter/services.dart';
8+
import 'package:flutter/widgets.dart';
9+
10+
const Color _grey = Color(0xFF9E9E9E);
11+
const Color _white = Color(0xFFFFFFFF);
12+
const Color _black = Color(0xFF000000);
13+
const Color _blue = Color(0xFF2196F3);
814

915
void main() {
1016
runApp(const FlutterView());
@@ -15,9 +21,23 @@ class FlutterView extends StatelessWidget {
1521

1622
@override
1723
Widget build(BuildContext context) {
18-
return MaterialApp(
24+
return WidgetsApp(
1925
title: 'Flutter View',
20-
theme: ThemeData(primarySwatch: Colors.grey),
26+
color: _grey,
27+
textStyle: const TextStyle(color: _black, decoration: TextDecoration.none),
28+
pageRouteBuilder: <T>(RouteSettings settings, WidgetBuilder builder) {
29+
return PageRouteBuilder<T>(
30+
settings: settings,
31+
pageBuilder:
32+
(
33+
BuildContext context,
34+
Animation<double> animation,
35+
Animation<double> secondaryAnimation,
36+
) {
37+
return builder(context);
38+
},
39+
);
40+
},
2141
home: const MyHomePage(),
2242
);
2343
}
@@ -60,32 +80,64 @@ class _MyHomePageState extends State<MyHomePage> {
6080

6181
@override
6282
Widget build(BuildContext context) {
63-
return Scaffold(
64-
body: Column(
65-
crossAxisAlignment: CrossAxisAlignment.start,
83+
return ColoredBox(
84+
color: _white,
85+
child: Stack(
6686
children: <Widget>[
67-
Expanded(
68-
child: Center(
69-
child: Text(
70-
'Platform button tapped $_counter time${_counter == 1 ? '' : 's'}.',
71-
style: const TextStyle(fontSize: 17.0),
87+
Column(
88+
crossAxisAlignment: CrossAxisAlignment.start,
89+
children: <Widget>[
90+
Expanded(
91+
child: Center(
92+
child: Text(
93+
'Platform button tapped $_counter time${_counter == 1 ? '' : 's'}.',
94+
style: const TextStyle(fontSize: 17.0),
95+
),
96+
),
7297
),
73-
),
98+
Container(
99+
padding: const EdgeInsets.only(bottom: 15.0, left: 5.0),
100+
child: Row(
101+
children: <Widget>[
102+
Image.asset('assets/flutter-mark-square-64.png', scale: 1.5),
103+
const Text('Flutter', style: TextStyle(fontSize: 30.0)),
104+
],
105+
),
106+
),
107+
],
74108
),
75-
Container(
76-
padding: const EdgeInsets.only(bottom: 15.0, left: 5.0),
77-
child: Row(
78-
children: <Widget>[
79-
Image.asset('assets/flutter-mark-square-64.png', scale: 1.5),
80-
const Text('Flutter', style: TextStyle(fontSize: 30.0)),
81-
],
109+
Positioned(
110+
bottom: 16.0,
111+
right: 16.0,
112+
child: _Button(
113+
onPressed: _sendFlutterIncrement,
114+
icon: const Text(
115+
'+',
116+
style: TextStyle(color: _white, fontSize: 28.0, fontWeight: FontWeight.bold),
117+
),
82118
),
83119
),
84120
],
85121
),
86-
floatingActionButton: FloatingActionButton(
87-
onPressed: _sendFlutterIncrement,
88-
child: const Icon(Icons.add),
122+
);
123+
}
124+
}
125+
126+
class _Button extends StatelessWidget {
127+
const _Button({required this.onPressed, required this.icon});
128+
129+
final VoidCallback onPressed;
130+
final Widget icon;
131+
132+
@override
133+
Widget build(BuildContext context) {
134+
return GestureDetector(
135+
onTap: onPressed,
136+
child: Container(
137+
width: 56.0,
138+
height: 56.0,
139+
decoration: const BoxDecoration(color: _blue, shape: BoxShape.circle),
140+
child: Center(child: icon),
89141
),
90142
);
91143
}

‎examples/flutter_view/pubspec.yaml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ dependencies:
1212

1313

1414
flutter:
15-
uses-material-design: true
1615
assets:
1716
- assets/flutter-mark-square-64.png
1817

0 commit comments

Comments
 (0)