text
stringlengths
1
372
<topic_start>
bundling images in apps
in SwiftUI, you first add the image files to assets.xcassets,
then use the image view to display the images.
to add images in flutter, follow a method similar to how you added
custom fonts.
add this asset to the pubspec.yaml file.
after adding your image, display it using the image widget’s
.asset() constructor. this constructor:
to review a complete example, check out the image docs.
<topic_end>
<topic_start>
bundling videos in apps
in SwiftUI, you bundle a local video file with your app in two
steps.
first, you import the AVKit framework, then you instantiate a
VideoPlayer view.
in flutter, add the video_player plugin to your project.
this plugin allows you to create a video player that works on
android, iOS, and on the web from the same codebase.
to review a complete walkthrough, check out the video_player example.
<topic_end>
<topic_start>
flutter for UIKit developers
iOS developers with experience using UIKit
who want to write mobile apps using flutter
should review this guide.
it explains how to apply existing UIKit knowledge to flutter.
info note
if you have experience building apps with SwiftUI,
check out flutter for SwiftUI developers instead.
flutter is a framework for building cross-platform applications
that uses the dart programming language.
to understand some differences between programming with dart
and programming with swift, see learning dart as a swift developer
and flutter concurrency for swift developers.
your iOS and UIKit knowledge and experience
are highly valuable when building with flutter.
flutter also makes a number of adaptations
to app behavior when running on iOS.
to learn how, see platform adaptations.
info
to integrate flutter code into an existing iOS app,
check out add flutter to existing app.
use this guide as a cookbook.
jump around and find questions that address your most relevant needs.
<topic_end>
<topic_start>
overview
as an introduction, watch the following video.
it outlines how flutter works on iOS and how to use flutter to build iOS apps.
<topic_end>
<topic_start>
views vs. widgets
how is react-style, or declarative,
programming different from the
traditional imperative style?
for a comparison, see introduction to declarative UI.
in UIKit, most of what you create in the UI is done using view objects,
which are instances of the UIView class.
these can act as containers for other UIView classes,
which form your layout.
in flutter, the rough equivalent to a UIView is a widget.
widgets don’t map exactly to iOS views,
but while you’re getting acquainted with how flutter works
you can think of them as “the way you declare and construct UI”.
however, these have a few differences to a UIView.
to start, widgets have a different lifespan: they are immutable
and only exist until they need to be changed.
whenever widgets or their state change,
flutter’s framework creates a new tree of widget instances.
in comparison, a UIKit view is not recreated when it changes,
but rather it’s a mutable entity that is drawn once
and doesn’t redraw until it is invalidated using setNeedsDisplay().
furthermore, unlike UIView, flutter’s widgets are lightweight,
in part due to their immutability.
because they aren’t views themselves,
and aren’t directly drawing anything,
but rather are a description of the UI and its semantics
that get “inflated” into actual view objects under the hood.
flutter includes the material components library.
these are widgets that implement the
material design guidelines.
material design is a flexible design system
optimized for all platforms, including iOS.
but flutter is flexible and expressive enough
to implement any design language.
on iOS, you can use the cupertino widgets
to produce an interface that looks like
apple’s iOS design language.
<topic_end>
<topic_start>
updating widgets
to update your views in UIKit, you directly mutate them.
in flutter, widgets are immutable and not updated directly.
instead, you have to manipulate the widget’s state.
this is where the concept of stateful vs stateless widgets
comes in. a StatelessWidget is just what it sounds
like—a widget with no state attached.
StatelessWidgets are useful when the part of the user interface you are