Showing posts with label iOS. Show all posts
Showing posts with label iOS. Show all posts

Friday, 17 April 2020

How to fix notch overlap in Flutter Basic Widgets example code

Problem:

I am learning Flutter, and the app bar on top in the Basic Widgets section of the Introduction to widgets section of the Flutter docs is being blocked by the notch of an iPhone or phone simulator, as seen below. How can I fix this?

Notes:

This bug was confirmed in April 2020. It's possible that the Flutter team has updated their documentation by the time you are reading this. (If so, thank you Flutter team!)

Also note that this how-to is just one way to workaround the issue. The later code in the Flutter documentation shows better practices on which widgets to use, etc., to avoid the notch. That being said, this workaround is for anyone who is trying to debug this before moving on.

Workaround:

The workaround is highlighted below, followed by a brief explanation:

import 'package:flutter/material.dart';

class MyAppBar extends StatelessWidget {
  MyAppBar({this.title});

  // Fields in a Widget subclass are always marked "final".

  final Widget title;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 56.0, // in logical pixels
      padding: const EdgeInsets.symmetric(horizontal: 8.0),
      decoration: BoxDecoration(color: Colors.blue[500]),
      // Row is a horizontal, linear layout.
      child: Row(
        //  is the type of items in the list.
        children: [
          IconButton(
            icon: Icon(Icons.menu),
            tooltip: 'Navigation menu',
            onPressed: null, // null disables the button
          ),
          // Expanded expands its child to fill the available space.
          Expanded(
            child: title,
          ),
          IconButton(
            icon: Icon(Icons.search),
            tooltip: 'Search',
            onPressed: null,
          ),
        ],
      ),
    );
  }
}

class MyScaffold extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // Material is a conceptual piece of paper on which the UI appears.
    return Material(
      child: SafeArea(
        // Column is a vertical, linear layout.
        child: Column(
          children: [
            MyAppBar(
              title: Text(
                'Example title',
                style: Theme.of(context).primaryTextTheme.title,
              ),
            ),
            Expanded(
              child: Center(
                child: Text('Hello, world!'),
              ),
            ),
          ],
        ),
      ), // SafeArea
    ); // Material
  }
}

void main() {
  runApp(MaterialApp(
    title: 'My app', // used by the OS task switcher
    home: MyScaffold(),
  ));
}

The above code encloses the other widgets in the example code within the safe area of the device via the SafeArea widget - a class that adds appropriate insets for a given device.

If all went well, your results should now look similar to the image below and you can now move on to learning more Flutter, free from the iPhone-notch-overlap.

If you'd like to learn more, please check out the references below.



References:

Tuesday, 25 September 2012

Workaround for ios6 Phonegap 2.0.0 linker error

Problem:

After upgrading to ios6 and XCode 4.5, when trying to compile my old PhoneGap/Cordova project on an iOS device I get the following error:

"_OBJC_CLASS_$_CDVURLProtocol", referenced from:
Objc-class-ref in AppDelegate.o
"_OBJC_CLASS_$_CDVViewController", referenced from:
_OBJC_CLASS_$_MainViewController in MainViewController.o
"_OBJC_METACLASS_$_CDVViewController", referenced from:
_OBJC_METACLASS_$_MainViewController in MainViewController.o
Symbol(s) not found for architecture armv7s

This error may not necessarily show up when running the program in the simulator.

Temporary workaround:

To have your old PhoneGap project working again, you can try the following:

  • in XCode 4.5, click on your project and click "build settings"
  • change Architecture to "Standard (armv7, armv7s)"
  • change Valid Architectures to be only "armv7, armv7s"
  • change Build Active Architecture Only to "Yes"

You may also have to do this for the linked CordovaLib.xcodeproj. This temporary workaround assumes that you have been using a build configuration similar to the default configuration (e.g. things haven't been heavily customized).

Notes:

This workaround won't work for projects using older versions that import PhoneGap as a precompiled framework. It should work for versions that import CordovaLib.xcodeproj, but no guarantees.

Keep a lookout for updates with the Apache Cordova/PhoneGap project as this workaround is only a temporary fix for those looking to test their old projects after upgrading their devices to iOS6. Chances are that this bug will be fixed by the PhoneGap team, if it already hasn't been. This workaround will result in dropped support for older ios devices (as the armv7s instruction set isn't supported by devices older than the iPhone 3GS). This workaround was tested with XCode 4.5 and Apache Cordova 2.0.0 on devices with the old 3.5 inch retina screen, recently upgraded to ios6. This workaround has not been tested in a deployed/production setting.

Friday, 11 May 2012

Fullscreen PhoneGap app with XCode

Problem:

How can I get rid of the status bar on top of my PhoneGap application on my iOS device?

Solution:

There are several ways to do this, and although I won't go into all of the ones I found, one of the easiest ways to do this is to just edit your project's Info.plist file. This is generally named in the form of "YourAppName-Info.plist".

In your plist file, secondary-click and add a row. Name this row UIStatusBarHidden, and change its type to Boolean. Note that if a drop-down menu appears and gives you the option to select "Status bar is initially hidden", pick that. In both cases, set the value to YES.

The next screenshot is an example where the choice is given to initially hide the status bar:

The next time you run your PhoneGap application, you'll now notice that it is fullscreen. This will continue to be the case until your application code does anything to change this, (for instance, if you try to send the user to a different page).


Other thoughts:

This was tested with PhoneGap version 1.5.0 (codename Cordova) on iOS 5.1, using XCode 4.3.2. Your mileage might vary with different versions. Also note that these instructions can be used to initially hide the status bar in any iOS application, not necessarily just PhoneGap applications.