Hayden Slater

1572582920

Building a Flutter app changes the size layout and screen orientation.

In this Flutter Responsive Design tutorial you’ll learn how to build a Flutter app that responds to layout changes such as screen size and orientation.

Sometimes the configuration changes for an app on a mobile device. Maybe a keyboard suddenly appears, or the user rotates the device. Or perhaps you want to display your app on both small and large devices.

At any rate, your app needs to be responsive to these layout changes. If you use Responsive Design, it will.

In this Flutter tutorial, you’ll:

  • Build a chat app in Flutter that responds to layout changes.

  • Learn to use Flutter’s MediaQuery, LayoutBuilder, OrientationBuilder, FittedBox and AspectRatio widgets.

  • Learn to handle orientation changes.

  • Perform text resizing.

  • Constrain a child widget in a column.

  • Learn about the idea of the CustomMultiChildLayout widget.

Note: This tutorial assumes that you’re already familiar with the basics of Flutter development. If you’re new to Flutter, read through the Getting Started With Flutter tutorial. You should also have knowledge of using Android Studio with Flutter.

What is Responsive Design?

The concept of Responsive Design is all about using one set of code that respond to various changes to layout. Platforms such as the iOS and Android native SDKs tackled this issue with “universal layouts.” The universal layouts respond to layout changes by using constraints and automatically resizing elements.

There are a variety of reasons why layout needs to responsively change from initial designs.

Handling Different Device Types and Screen Sizes

This is image title

Your Flutter app can run on a phone, tablet, TV screen or (when they start supporting it) watch. Even within the category of phones there’s a large array of different resolutions and screen sizes. You need to make sure that the layout works as intended for each device type and screen size. Additionally, you can have different layouts for each device type and screen size.

With this in mind, Flutter provides several widgets and classes for responsive design. You’ll learn about some of these in this tutorial.

Handling Keyboard State Changes

Your interface might have text fields. The keyboard pops up when the user starts interacting with those fields. When that keyboard pops up, so do layout issues.

Android handles this with configuration changes for the keyboard. iOS uses internal notifications for keyboard state changes. But in Flutter, the Scaffold class automatically handles keyboard state changes.

In detail, Scaffold adjusts the bottom insets to make room for the keyboard. You can, however, disable this behavior by setting the resizeToAvoidBottomInset property to false.

You can read more about Scaffold‘s interaction with the keyboard here.

Handling Orientation Changes

Let’s face it, users can rotate their device, and will do so frequently. You could disable responding to this within your app, locking your app into portrait or landscape mode, but your app wouldn’t be as fun and might in fact be less useful with respect to user experience.

When rotation happens in Flutter, MediaQuery can help rebuild your layout. MaterialApp and WidgetsApp already use MediaQuery. If you use them, Flutter rebuilds your widgets under MaterialApp if orientation changes.

You can read more about MediaQuery here.

Now that you understand the reasons for Responsive Design, it’s time to see what Flutter widgets can do to help.

Getting Started

Download the starter project by clicking on the Download Materials button at the top or bottom of the tutorial. Then, open the starter project in Android Studio 3.4 or later. You can also use VS Code, but you’ll have to adapt instructions below as needed.

You should be using a recent version of Flutter, 1.5 or above. Be sure to get Flutter dependencies for the project if prompted to do so by Android Studio with a ‘Packages get’ has not been run message.

You’ll find the starter project provides some parts of the chat app you’ll be working with.

Using MediaQuery to Decide the Layout

Now you should try using MediaQuery to determine the layout. This is just one of the options you can use to respond to layout changes. You’ll get to use the other options in the next sections.

Go into the ChatListPage.dart file in the lib folder. Replace the contents of build(BuildContext context) with:


// 1
var hasDetailPage =
    MediaQuery.of(context).orientation == Orientation.landscape;
// 2
Widget child;

if (hasDetailPage) {
  // 3
  child = Row(
    children: [
      // 4
      SizedBox(
        width: 250,
        height: double.infinity,
        child: _buildList(context, hasDetailPage),
      ),
      // 5
      Expanded(child: _buildChat(context, selectedIndex)),
    ],
  );
} else {
  // 6
  child = _buildList(context, hasDetailPage);
}

return Scaffold(
  appBar: AppBar(
    title: Text("Chats"),
  ),
  body: SafeArea(
    // 7
    child: child,
  ),
);


With that, you layout the chat page using MediaQuery. Here’s what you did:

  1. First, you check the orientation from MediaQuery. If it’s landscape, then you have a details page.

  2. Second, you declare a child widget to use later.

  3. Next, if you have a details page, you declare the child as a row of widgets.

  4. For this, the row contains the list of chats as a first item.

  5. Then, the next item in the row is the chat page showing the conversation.

  6. If you don’t have a details page, the child will be the list of chats.

  7. Finally, you need to assign that child widget you created as a child of SafeArea.

Build and run the project — you should see a screen like this for portrait:

This is image title

And this for landscape:

This is image title

You’ll notice the layout is different for portrait and landscape. You can also try running it on a different device like a tablet.

Using Widgets in Responsive Design

As mentioned previously, there are other widgets that achieve the same effect as MediaQuery. For example, LayoutBuilder allows you to do the same thing. You’ll see that in this section.

Aside from that, there are other layout problems with the chat app. For instance, the text size on the user avatar does not scale. You will fix that in a bit.

Using LayoutBuilder and OrientationBuilder

LayoutBuilder and OrientationBuilder are alternatives to MediaQuery for handling orientation changes. Time to see exactly how they work, starting with LayoutBuilder.

First, open ChatListPage.dart, like you did in the previous section. Replace the contents of build(...) with this:


return Scaffold(
  appBar: AppBar(
    title: Text("Chats"),
  ),
  body: SafeArea(
    // 1
    child: LayoutBuilder(builder: (builder, constraints) {
      // 2
      var hasDetailPage = constraints.maxWidth > 600;

      if (hasDetailPage) {
        // 3
        return Row(
          children: [
            // 4
            SizedBox(
              width: 250,
              height: double.infinity,
              child: _buildList(context, hasDetailPage),
            ),
            // 5
            Expanded(child: _buildChat(context, selectedIndex)),
          ],
        );
      } else {
        // 6
        return _buildList(context, hasDetailPage);
      }
    }),
  ),
);


With that, you layout the chat page again, this time using LayoutBuilder. Here’s what you did:

  1. First, you declare a LayoutBuilder as the child of SafeArea.

  2. Second, you determine if you have a details page using the maximum width of the parent widget. If it is greater than 600, then you have a details page.

  3. Next, if you have a details page, you declare child as a row of widgets.

  4. For this, the row contains the list of chats as a first item.

  5. Then, the next item in the row is the chat page showing the conversation.

  6. Finally, if you don’t have a details page, it’ll be the list of chats.

Build and run the project. You should see the same screen in the different orientations as in the previous section.

If you also want to try OrientationBuilder, replace the lines with LayoutBuilder and the setting of hasDetailPage with this:

child: OrientationBuilder(builder: (builder, orientation) {  
  var hasDetailPage = orientation == Orientation.landscape;


This minor change has the same effect. Instead of reading the width of the parent widget, you read the parent widget’s orientation from the builder. If the orientation is landscape, then you have a details page.

Build and run the project. You should see the same screens as before. As you can see, each of these various widgets can solve the problem of different orientations and screen sizes.

Next, you’ll fix the text that’s not resizing in the user’s avatar.

Auto-Resizing Text Based on Parent Widget Size

As you can see in the landscape screenshot above, the text in the colored boxes for the user isn’t resizing properly to fill the box. You can’t just increase the size of the font because you might go over the box. The right way to do it is to allow the widget to scale according to the size of the parent widget.

The Flutter widget FittedBox can solve this problem.

Using FittedBox

Open AvatarImageView.dart in lib/widgets and check the contents of _buildContent(Color textColor). You can see here a Text widget that renders the initials of the user. The font size is 14. Surround the Text widget with a FittedBox like below:

// 1
return FittedBox(
  // 2
  fit: BoxFit.contain,
  // 3
  child: Text(
    initials,
    style: TextStyle(color: textColor, fontSize: 14),
  ),
);


This makes the Text widget fill the parent widget and follows the BoxFit.contain rules. Going over each line:

  1. First, you declare a FittedBox as a parent of the Text widget.

  2. Second, you use the BoxFit.contain fit to make it scale as big as it can without going out of the widget box.

  3. Finally, you declare the original Text widget as a child.

Build and run the project. You’ll see the following in landscape orientation:

This is image title

Now you see that the text has resized accordingly. In general, you can use other types of BoxFit. You can see how each of them behave in the image below:

This is image title

Providing Constraints to Children

There’s a paper clip image attachment button in your chat app. This should allow you to select images from a gallery. Usually, you want to display it within the chat view so you can still see the conversation while picking an image.

Right now, this is not displaying. Click on the attach button and you’ll only see the following for portrait:

This is image title

and this for landscape:

This is image title

Using AspectRatio

You need to fix the broken gallery. First, open the ConversationPage.dart file in the lib folder. Then look for the line with SquareGallery() with a TODO.

That widget isn’t appearing because it’s a child of Column and it doesn’t have enough information to determine its own height. So, wrap it in a AspectRatio widget to give it constraints. Replace the SquareGallery() line with the following:

AspectRatio(
  aspectRatio: 3,
  child: SquareGallery(),
),


Now that the gallery is wrapped in AspectRatio, it’ll have a constraint that tries to follow the provided ratio. It’ll be three times wider than it is high. In addition, AspectRatio will try to find constraints that fit what you provided as ratio as well as the parent constraints.

However, if it can’t find such a constraint, it’ll give you one that follows only the ratio you provided. In that case, the widget might overflow.

Build and run the project. When clicking the image attachment button, you should see a screen like this for portrait:

This is image title

and this for landscape:

This is image title
Congratulations! Now you’ve fixed the layout issues in the app. You can finally be responsive again in the chats! :]

CustomMultiChildLayout

In addition to the basic widgets for responsive design, Flutter also provides a way to layout widgets on your own with CustomMultiChildLayout. You’ll now see how to use it, but only in theory. Because CustomMultiChildLayout is such a big topic, you’ll only see the basics here.

Check out the code snippet below:

CustomMultiChildLayout(
  delegate: delegate,
  children: widgets,
)


Here you declare a CustomMultiChildLayout with a custom delegate. The delegate can be an object of a class like the following:

// 1


// 1
class RWDelegate extends MultiChildLayoutDelegate {
  // 2
  @override
  void performLayout(Size size) {
    // Do your layout here
  }

  // 3
  @override
  bool shouldRelayout(MultiChildLayoutDelegate oldDelegate) => false;
}


Here’s what you did:

  1. First, you declare a subclass of MultiChildLayoutDelegate.

  2. Second, you override the performLayout method. Here you need to layout the children widgets using the layoutChild and positionChild methods.

  3. Finally, you return a boolean from shouldRelayout if the widget should perform a layout again. This method should decide based on your own widget’s parameters or state.

You can read the full docs for this widget here and for the delegate here. Look for a full tutorial on CustomMultiChildLayout on our Flutter page soon!

#Flutter #mobile #app

What is GEEK

Buddha Community

Building a Flutter app changes the size layout and screen orientation.

“Download Material” option does not available!

Google's Flutter 1.20 stable announced with new features - Navoki

Flutter Google cross-platform UI framework has released a new version 1.20 stable.

Flutter is Google’s UI framework to make apps for Android, iOS, Web, Windows, Mac, Linux, and Fuchsia OS. Since the last 2 years, the flutter Framework has already achieved popularity among mobile developers to develop Android and iOS apps. In the last few releases, Flutter also added the support of making web applications and desktop applications.

Last month they introduced the support of the Linux desktop app that can be distributed through Canonical Snap Store(Snapcraft), this enables the developers to publish there Linux desktop app for their users and publish on Snap Store.  If you want to learn how to Publish Flutter Desktop app in Snap Store that here is the tutorial.

Flutter 1.20 Framework is built on Google’s made Dart programming language that is a cross-platform language providing native performance, new UI widgets, and other more features for the developer usage.

Here are the few key points of this release:

Performance improvements for Flutter and Dart

In this release, they have got multiple performance improvements in the Dart language itself. A new improvement is to reduce the app size in the release versions of the app. Another performance improvement is to reduce junk in the display of app animation by using the warm-up phase.

sksl_warm-up

If your app is junk information during the first run then the Skia Shading Language shader provides for pre-compilation as part of your app’s build. This can speed it up by more than 2x.

Added a better support of mouse cursors for web and desktop flutter app,. Now many widgets will show cursor on top of them or you can specify the type of supported cursor you want.

Autofill for mobile text fields

Autofill was already supported in native applications now its been added to the Flutter SDK. Now prefilled information stored by your OS can be used for autofill in the application. This feature will be available soon on the flutter web.

flutter_autofill

A new widget for interaction

InteractiveViewer is a new widget design for common interactions in your app like pan, zoom drag and drop for resizing the widget. Informations on this you can check more on this API documentation where you can try this widget on the DartPad. In this release, drag-drop has more features added like you can know precisely where the drop happened and get the position.

Updated Material Slider, RangeSlider, TimePicker, and DatePicker

In this new release, there are many pre-existing widgets that were updated to match the latest material guidelines, these updates include better interaction with Slider and RangeSliderDatePicker with support for date range and time picker with the new style.

flutter_DatePicker

New pubspec.yaml format

Other than these widget updates there is some update within the project also like in pubspec.yaml file format. If you are a flutter plugin publisher then your old pubspec.yaml  is no longer supported to publish a plugin as the older format does not specify for which platform plugin you are making. All existing plugin will continue to work with flutter apps but you should make a plugin update as soon as possible.

Preview of embedded Dart DevTools in Visual Studio Code

Visual Studio code flutter extension got an update in this release. You get a preview of new features where you can analyze that Dev tools in your coding workspace. Enable this feature in your vs code by _dart.previewEmbeddedDevTools_setting. Dart DevTools menu you can choose your favorite page embed on your code workspace.

Network tracking

The updated the Dev tools comes with the network page that enables network profiling. You can track the timings and other information like status and content type of your** network calls** within your app. You can also monitor gRPC traffic.

Generate type-safe platform channels for platform interop

Pigeon is a command-line tool that will generate types of safe platform channels without adding additional dependencies. With this instead of manually matching method strings on platform channel and serializing arguments, you can invoke native class and pass nonprimitive data objects by directly calling the Dartmethod.

There is still a long list of updates in the new version of Flutter 1.2 that we cannot cover in this blog. You can get more details you can visit the official site to know more. Also, you can subscribe to the Navoki newsletter to get updates on these features and upcoming new updates and lessons. In upcoming new versions, we might see more new features and improvements.

You can get more free Flutter tutorials you can follow these courses:

#dart #developers #flutter #app developed #dart devtools in visual studio code #firebase local emulator suite in flutter #flutter autofill #flutter date picker #flutter desktop linux app build and publish on snapcraft store #flutter pigeon #flutter range slider #flutter slider #flutter time picker #flutter tutorial #flutter widget #google flutter #linux #navoki #pubspec format #setup flutter desktop on windows

Idrish Dhankot

Idrish Dhankot

1622532470

Hire Dedicated Flutter App Developer USA| Flutter App Developers

Hire Flutter App Developers: WebClues Infotech is a Flutter App Development company. Our Flutter mobile app development team can create cross-platform apps for different industry verticals. Our Flutter developers will help you extend your business’s scope by developing enhanced functionality and a feature-rich app. To provide a rich user experience to your users, hire dedicated Flutter app developers from WebClues Infotech today!

#hire flutter app developers #hire dedicated flutter app developer usa #hire flutter app developer usa #hire dedicated flutter app developer #hire flutter developer #flutter app development company

Best Flutter App Development Company

Are you looking for the best flutter app development company? Then AppClues Infotech is the leading flutter app development company in USA offering the best service worldwide. We focused on developing hybrid mobile apps on Android & iOS and assures our end-user about exceptional and functionally-rich mobile apps.

For more info:
Website: https://www.appcluesinfotech.com/
Email: info@appcluesinfotech.com
Call: +1-978-309-9910

#top flutter app development company in usa #best flutter app development service #best flutter app development company #hire flutter app developers #flutter app development company #expert flutter app development company

Best Flutter App Development Company in USA & India

AppClues Infotech is one of the best flutter app development company in USA & India. Our diverse and experienced team of developers can help you sketch the smartest and quickest solution for your mobile app development projects with the most superior technology.

For more info:
Website: https://www.appcluesinfotech.com/
Email: info@appcluesinfotech.com
Call: +1-978-309-9910

#top flutter app development company in usa #best flutter app development service #best flutter app development company #hire flutter app developers #flutter app development company in usa & india #custom flutter app development service

Punith Raaj

1644991598

The Ultimate Guide To Tik Tok Clone App With Firebase - Ep 2

The Ultimate Guide To Tik Tok Clone App With Firebase - Ep 2
In this video, I'm going to show you how to make a Cool Tik Tok App a new Instagram using Flutter,firebase and visual studio code.

In this tutorial, you will learn how to Upload a Profile Pic to Firestore Data Storage.

🚀 Nice, clean and modern TikTok Clone #App #UI made in #Flutter⚠️

Starter Project : https://github.com/Punithraaj/Flutter_Tik_Tok_Clone_App/tree/Episode1

► Timestamps 
0:00 Intro 0:20 
Upload Profile Screen 
16:35 Image Picker
20:06 Image Cropper 
24:25 Firestore Data Storage Configuration.

⚠️ IMPORTANT: If you want to learn, I strongly advise you to watch the video at a slow speed and try to follow the code and understand what is done, without having to copy the code, and then download it from GitHub.

► Social Media 
GitHub: https://github.com/Punithraaj/Flutter_Tik_Tok_Clone_App.git
LinkedIn: https://www.linkedin.com/in/roaring-r...
Twitter: https://twitter.com/roaringraaj
Facebook: https://www.facebook.com/flutterdartacademy

► Previous Episode : https://youtu.be/QnL3fr-XpC4
► Playlist: https://youtube.com/playlist?list=PL6vcAuTKAaYe_9KQRsxTsFFSx78g1OluK

I hope you liked it, and don't forget to like,comment, subscribe, share this video with your friends, and star the repository on GitHub!
⭐️ Thanks for watching the video and for more updates don't forget to click on the notification. 
⭐️Please comment your suggestion for my improvement. 
⭐️Remember to like, subscribe, share this video, and star the repo on Github :)

Hope you enjoyed this video!
If you loved it, you can Buy me a coffee : https://www.buymeacoffee.com/roaringraaj

LIKE & SHARE & ACTIVATE THE BELL Thanks For Watching :-)
 
https://youtu.be/F_GgZVD4sDk

#flutter tutorial - tiktok clone with firebase #flutter challenge @tiktokclone #fluttertutorial firebase #flutter firebase #flutter pageview #morioh #flutter