Skip to content

Commit c586d72

Browse files
Add content resizing sample (#2756)
Add a content resizing sample for iOS to support flutter/flutter#177410 ## Pre-launch Checklist - [x] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I read the [Contributors Guide]. - [x] I have added sample code updates to the [changelog]. - [x] I updated/added relevant documentation (doc comments with `///`). If you need help, consider asking for advice on the #hackers-devrel channel on [Discord]. <!-- Links --> [Flutter Style Guide]: https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md [Contributors Guide]: https://github.com/flutter/samples/blob/main/CONTRIBUTING.md [changelog]: ../CHANGELOG.md --------- Co-authored-by: Eric Windmill <eric@ericwindmill.com>
1 parent ebdd823 commit c586d72

File tree

99 files changed

+5335
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+5335
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# ios_content_resizing
2+
3+
Embeds an instance of Flutter into an existing iOS app that will dynamically resize itself based off of it's content.
4+
5+
## Description
6+
7+
This sample showcases the integration of a self-resizing Flutter view within a native UIKit environment. The Flutter module features an expanding column of widgets. As items are added, the hosting UIView will automatically adjusts its [intrinsicContentSize](https://developer.apple.com/documentation/uikit/uiview/intrinsiccontentsize) to accommodate the new content size.
8+
9+
## tl;dr
10+
11+
If you're just looking to get up and running quickly, these bash commands will
12+
fetch packages and set up dependencies (note that the above commands assume
13+
you're building for both iOS and Android, with both toolchains installed):
14+
15+
```bash
16+
#!/bin/bash
17+
set -e
18+
19+
cd flutter_module/
20+
flutter pub get
21+
22+
# For iOS builds:
23+
cd ../ios_content_resizing
24+
pod install
25+
open ios_content_resizing.xcworkspace
26+
# Then, click "Run" in Xcode to launch the app into your Simulator or device
27+
```
28+
29+
## Requirements
30+
31+
* Flutter
32+
* iOS
33+
* Xcode
34+
* Cocoapods
35+
36+
## Questions/issues
37+
38+
See [add_to_app/README.md](../README.md) for further help.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.DS_Store
2+
.dart_tool/
3+
4+
.pub/
5+
6+
.idea/
7+
.vagrant/
8+
.sconsign.dblite
9+
.svn/
10+
11+
migrate_working_dir/
12+
13+
*.swp
14+
profile
15+
16+
DerivedData/
17+
18+
.generated/
19+
20+
*.pbxuser
21+
*.mode1v3
22+
*.mode2v3
23+
*.perspectivev3
24+
25+
!default.pbxuser
26+
!default.mode1v3
27+
!default.mode2v3
28+
!default.perspectivev3
29+
30+
xcuserdata
31+
32+
*.moved-aside
33+
34+
*.pyc
35+
*sync/
36+
Icon?
37+
.tags*
38+
39+
build/
40+
.android/
41+
.ios/
42+
.flutter-plugins-dependencies
43+
44+
# Symbolication related
45+
app.*.symbols
46+
47+
# Obfuscation related
48+
app.*.map.json
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "27ccc2e66f3fd85ad388e3ba038a89251aef41b7"
8+
channel: "master"
9+
10+
project_type: module
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# flutter_module
2+
3+
A new Flutter module project.
4+
5+
## Getting Started
6+
7+
For help getting started with Flutter development, view the online
8+
[documentation](https://flutter.dev/).
9+
10+
For instructions integrating Flutter modules to your existing applications,
11+
see the [add-to-app documentation](https://flutter.dev/to/add-to-app).
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
# Additional information about this file can be found at
4+
# https://dart.dev/guides/language/analysis-options
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 'package:flutter/material.dart';
6+
7+
void main() {
8+
runApp(const ResizeApp());
9+
}
10+
11+
class ResizeApp extends StatefulWidget {
12+
const ResizeApp({super.key});
13+
14+
@override
15+
State<ResizeApp> createState() => _ResizeAppState();
16+
}
17+
18+
class _ResizeAppState extends State<ResizeApp> {
19+
int _listSize = 1;
20+
void _addToList() {
21+
setState(() {
22+
_listSize++;
23+
});
24+
}
25+
26+
@override
27+
Widget build(BuildContext context) {
28+
return Center(
29+
heightFactor: 1,
30+
child: Directionality(
31+
textDirection: TextDirection.ltr,
32+
child: Column(
33+
mainAxisSize: MainAxisSize.min,
34+
children: <Widget>[
35+
for (int i = 0; i < _listSize; i++)
36+
Container(color: HSVColor.fromAHSV(1, (10.0 * i), 1, 1).toColor(), height: 50, width: 200,
37+
child: Center(
38+
child: Text(
39+
'Flutter Widget $i',
40+
style: const TextStyle(fontSize: 16, color: Colors.black),
41+
),
42+
)),
43+
TextButton(
44+
onPressed: _addToList,
45+
child: Text('Listception!'),
46+
)
47+
],
48+
),
49+
),
50+
);
51+
}
52+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: flutter_module
2+
description: "A new Flutter module project."
3+
4+
# The following defines the version and build number for your application.
5+
# A version number is three numbers separated by dots, like 1.2.43
6+
# followed by an optional build number separated by a +.
7+
# Both the version and the builder number may be overridden in flutter
8+
# build by specifying --build-name and --build-number, respectively.
9+
# In Android, build-name is used as versionName while build-number used as versionCode.
10+
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
11+
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
12+
# Read more about iOS versioning at
13+
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
14+
#
15+
# This version is used _only_ for the Runner app, which is used if you just do
16+
# a `flutter run`. It has no impact on any other native host app that you embed
17+
# your Flutter project into.
18+
version: 1.0.0+1
19+
20+
environment:
21+
sdk: ^3.11.0-200.1.beta
22+
23+
dependencies:
24+
flutter:
25+
sdk: flutter
26+
27+
# The following adds the Cupertino Icons font to your application.
28+
# Use with the CupertinoIcons class for iOS style icons.
29+
cupertino_icons: ^1.0.8
30+
31+
dev_dependencies:
32+
flutter_test:
33+
sdk: flutter
34+
flutter_lints: ^6.0.0
35+
36+
# For information on the generic Dart part of this file, see the
37+
# following page: https://dart.dev/tools/pub/pubspec
38+
39+
flutter:
40+
# The following line ensures that the Material Icons font is
41+
# included with your application, so that you can use the icons in
42+
# the material Icons class.
43+
uses-material-design: true
44+
45+
# To add Flutter specific assets to your application, add an assets section,
46+
# like this:
47+
# assets:
48+
# - images/a_dot_burr.jpeg
49+
# - images/a_dot_ham.jpeg
50+
51+
# An image asset can refer to one or more resolution-specific "variants", see
52+
# https://flutter.dev/to/resolution-aware-images
53+
54+
# For details regarding adding assets from package dependencies, see
55+
# https://flutter.dev/to/asset-from-package
56+
57+
# To add Flutter specific custom fonts to your application, add a fonts
58+
# section here, in this "flutter" section. Each entry in this list should
59+
# have a "family" key with the font family name, and a "fonts" key with a
60+
# list giving the asset and other descriptors for the font. For
61+
# example:
62+
# fonts:
63+
# - family: Schyler
64+
# fonts:
65+
# - asset: fonts/Schyler-Regular.ttf
66+
# - asset: fonts/Schyler-Italic.ttf
67+
# style: italic
68+
# - family: Trajan Pro
69+
# fonts:
70+
# - asset: fonts/TrajanPro.ttf
71+
# - asset: fonts/TrajanPro_Bold.ttf
72+
# weight: 700
73+
#
74+
# For details regarding fonts from package dependencies,
75+
# see https://flutter.dev/to/font-from-package
76+
77+
78+
# This section identifies your Flutter project as a module meant for
79+
# embedding in a native host app. These identifiers should _not_ ordinarily
80+
# be changed after generation - they are used to ensure that the tooling can
81+
# maintain consistency when adding or modifying assets and plugins.
82+
# They also do not have any bearing on your native host application's
83+
# identifiers, which may be completely independent or the same as these.
84+
module:
85+
androidX: true
86+
androidPackage: com.example.flutter_module
87+
iosBundleIdentifier: com.example.flutterModule
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Uncomment the next line to define a global platform for your project
2+
# platform :ios, '15.0'
3+
4+
flutter_application_path = '../flutter_module'
5+
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
6+
7+
8+
target 'ios_content_resizing' do
9+
# Comment the next line if you don't want to use dynamic frameworks
10+
use_frameworks!
11+
12+
# Pods for ios_content_resizing
13+
14+
install_all_flutter_pods(flutter_application_path)
15+
16+
target 'ios_content_resizingTests' do
17+
inherit! :search_paths
18+
# Pods for testing
19+
end
20+
21+
target 'ios_content_resizingUITests' do
22+
# Pods for testing
23+
end
24+
25+
end
26+
27+
28+
post_install do |installer|
29+
flutter_post_install(installer) if defined?(flutter_post_install)
30+
end
31+
32+

add_to_app/ios_content_resizing/ios_content_resizing/Pods/Local Podspecs/Flutter.podspec.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

add_to_app/ios_content_resizing/ios_content_resizing/Pods/Local Podspecs/FlutterPluginRegistrant.podspec.json

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)