flutter icon indicating copy to clipboard operation
flutter copied to clipboard

Updating an App on timezone or timezone definition changes

Open HansMuller opened this issue 7 years ago • 19 comments

Currently Flutter apps are rebuilt when the device's locale setting is changed.

It's not clear how well we respond when the device's time zone changes or when time zone definitions change (which can actually happen).

HansMuller avatar Oct 13 '17 16:10 HansMuller

Any progress on this?

leedstyh avatar Oct 12 '18 09:10 leedstyh

Can't find a way to test this. Is this still a relevant issue?

markusaksli-nc avatar Sep 07 '20 12:09 markusaksli-nc

I tried to reproduce this issue with counter example on the Android device Changing timezone, language, or region doesn't reset the counter

ezgif com-resize

code sample
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
        // This makes the visual density adapt to the platform that you run
        // the app on. For desktop platforms, the controls will be smaller and
        // closer together (more dense) than on mobile platforms.
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also a layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Invoke "debug painting" (press "p" in the console, choose the
          // "Toggle Debug Paint" action from the Flutter Inspector in Android
          // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
          // to see the wireframe for each widget.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

flutter doctor -v
✓] Flutter (Channel master, 1.22.0-10.0.pre.88, on Mac OS X 10.15.6 19G2021,
    locale en-GB)
    • Flutter version 1.22.0-10.0.pre.88 at
      /Users/tahatesser/Code/flutter_master
    • Framework revision e10bdbbd9d (18 hours ago), 2020-09-07 11:40:03 -0700
    • Engine revision ac8b9c4c52
    • Dart version 2.10.0 (build 2.10.0-86.0.dev)

 
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/tahatesser/Code/sdk
    • Platform android-30, build-tools 30.0.2
    • ANDROID_HOME = /Users/tahatesser/Code/sdk
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.7)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.7, Build version 11E801a
    • CocoaPods version 1.9.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 49.0.2
    • Dart plugin version 193.7547
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.48.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.14.1

 
[✓] Connected device (4 available)            
    • RMX2001 (mobile)   • EUYTFEUSQSRGDA6D                     • android-arm64
      • Android 10 (API 29)
    • iPhone 11 (mobile) • 73130414-6DF8-4E37-B9AF-F81FA0F9068B • ios
      • com.apple.CoreSimulator.SimRuntime.iOS-13-7 (simulator)
    • Web Server (web)   • web-server                           • web-javascript
      • Flutter Tools
    • Chrome (web)       • chrome                               • web-javascript
      • Google Chrome 85.0.4183.83

• No issues found!

Similar https://github.com/flutter/flutter/issues/13703 This requires full app restart to get a new time format after changing it from settings

TahaTesser avatar Sep 08 '20 12:09 TahaTesser

@HansMuller Is this still something we want to get done? The work would likely be passing time zone information either alongside the localization channel updates or maybe in its own message in each embedder.

GaryQian avatar Oct 19 '20 20:10 GaryQian

From https://github.com/flutter/flutter/issues/13703, changing time format to/from 24hr format on iOS is not respected either without a restart.

GaryQian avatar Oct 19 '20 20:10 GaryQian

iOS 24hr repro: https://github.com/flutter/flutter/issues/13703#issuecomment-688337226

GaryQian avatar Oct 19 '20 21:10 GaryQian

complete code sample
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Material App',
      theme: ThemeData.dark(),
      home: Home(),
    );
  }
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final value = MediaQueryData.fromWindow(WidgetsBinding.instance.window)
        .alwaysUse24HourFormat;

    return Scaffold(
      appBar: AppBar(
        title: Text('Material App Bar'),
      ),
      body: Center(
        child: Container(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              Text(
                'MediaQueryData.fromWindow(WidgetsBinding.instance.window).alwaysUse24HourFormat',
                textAlign: TextAlign.center,
              ),
              Text(value.toString()),
            ],
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: () {},
      ),
    );
  }
}

flutter doctor -v
[✓] Flutter (Channel master, 1.24.0-2.0.pre.98, on Mac OS X 10.15.7 19H2
    darwin-x64, locale en-GB)
    • Flutter version 1.24.0-2.0.pre.98 at /Users/tahatesser/Code/flutter_master
    • Framework revision a4ac7cce82 (7 hours ago), 2020-10-21 00:46:59 -0400
    • Engine revision c2c74ed708
    • Dart version 2.11.0 (build 2.11.0-240.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/tahatesser/Code/sdk
    • Platform android-30, build-tools 30.0.2
    • ANDROID_HOME = /Users/tahatesser/Code/sdk
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.1, Build version 12A7403
    • CocoaPods version 1.10.0.rc.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.50.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.15.1

[✓] Connected device (6 available)
    • RMX2001 (mobile)           • EUYTFEUSQSRGDA6D                     •
      android-arm64  • Android 10 (API 29)
    • Taha’s iPhone (mobile)     • 00008020-001059882212002E            • ios
      • iOS 14.1
    • iPhone 12 Pro Max (mobile) • 1D3E6751-99F7-4E2E-B3DC-B3BEC4BB606F • ios
      • com.apple.CoreSimulator.SimRuntime.iOS-14-1 (simulator)
    • macOS (desktop)            • macos                                •
      darwin-x64     • Mac OS X 10.15.7 19H2 darwin-x64
    • Web Server (web)           • web-server                           •
      web-javascript • Flutter Tools
    • Chrome (web)               • chrome                               •
      web-javascript • Google Chrome 86.0.4240.80

• No issues found!

TahaTesser avatar Oct 21 '20 11:10 TahaTesser

The MediaQuery.of(context).alwaysUse24HourFormat still needs a full restart of the app to be updated

marcodecarolisidt avatar Apr 22 '21 05:04 marcodecarolisidt

Any updates?

b3nni97 avatar May 22 '21 23:05 b3nni97

This is still an issue on Flutter 2.5.3 for. I hope I'm doing something wrong, but AFAIK we still need app restart (I am trying to detect time-format setting on Android).

gosusnjar avatar Dec 13 '21 20:12 gosusnjar

Any update ?, i still have issue when i'm changing time zone in setting app, my application not detected the change until i restart my phone (testing on android 7.0)

longhoang123 avatar May 04 '22 04:05 longhoang123

Please change this in windows and linux also

Remigiusz-Ruszkiewicz avatar May 26 '22 04:05 Remigiusz-Ruszkiewicz

@GaryQian can you force this issue to be fixed?

Remigiusz-Ruszkiewicz avatar May 26 '22 09:05 Remigiusz-Ruszkiewicz

Hello anybody work here ? do we have to fix it myself and make mr? or someone is working on it?

Remigiusz-Ruszkiewicz avatar Jun 21 '22 08:06 Remigiusz-Ruszkiewicz

@huycozy any update?

Remigiusz-Ruszkiewicz avatar Aug 16 '22 08:08 Remigiusz-Ruszkiewicz

still an issue https://stackoverflow.com/questions/76456882/getting-time-format-from-device-settings-when-app-resumed-on-flutter/76458815?noredirect=1#comment134822847_76458815

OlegBezr avatar Jun 17 '23 09:06 OlegBezr

BUMP!!!

Remigiusz-Ruszkiewicz avatar Jun 27 '23 05:06 Remigiusz-Ruszkiewicz

is there any updates on this issue? it is still a problem that is out there for 7 years ...

Remigiusz-Ruszkiewicz avatar Feb 15 '24 11:02 Remigiusz-Ruszkiewicz

Reproduced this issue on the latest stable/master channels using sample code at https://github.com/flutter/flutter/issues/12531#issuecomment-713505193 (on Android app)

flutter doctor -v (stable and master)
[✓] Flutter (Channel stable, 3.19.0, on macOS 14.1 23B74 darwin-x64, locale en-VN)
    • Flutter version 3.19.0 on channel stable at /Users/huynq/Documents/GitHub/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision bae5e49bc2 (2 days ago), 2024-02-13 17:46:18 -0800
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
    • Android Studio at /Applications/Android Studio Hedgehog.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = /Applications/Android Studio.app/
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.86.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.82.0

[✓] Connected device (3 available)
    • RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64  • Android 11 (API 30)
    • macOS (desktop)  • macos            • darwin-x64     • macOS 14.1 23B74 darwin-x64
    • Chrome (web)     • chrome           • web-javascript • Google Chrome 121.0.6167.160
    ! Error: Browsing on the local area network for iPad. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources
    • All expected network resources are available.

• No issues found!
[!] Flutter (Channel master, 3.20.0-7.0.pre.79, on macOS 14.1 23B74 darwin-x64, locale en-VN)
    • Flutter version 3.20.0-7.0.pre.79 on channel master at /Users/huynq/Documents/GitHub/flutter_master
    ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7b9f7be7f6 (38 minutes ago), 2024-02-15 18:13:21 -0800
    • Engine revision bc4dd534a0
    • Dart version 3.4.0 (build 3.4.0-143.0.dev)
    • DevTools version 2.33.0-dev.6
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
    • Android Studio at /Applications/Android Studio Hedgehog.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = /Applications/Android Studio.app/
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.86.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.82.0

[✓] Connected device (4 available)
    • RMX2001 (mobile) • EUYTFEUSQSRGDA6D          • android-arm64  • Android 11 (API 30)
    • iPad (mobile)    • 00008103-000A1464346A201E • ios            • iOS 17.2 21C62
    • macOS (desktop)  • macos                     • darwin-x64     • macOS 14.1 23B74 darwin-x64
    • Chrome (web)     • chrome                    • web-javascript • Google Chrome 121.0.6167.160

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

huycozy avatar Feb 16 '24 11:02 huycozy

Are there any updates on this issue? Or does anyone have a workaround (except restarting the app - not an option)?

lisaerikssonw avatar May 21 '24 19:05 lisaerikssonw

yep any update?

Remigiusz-Ruszkiewicz avatar May 22 '24 05:05 Remigiusz-Ruszkiewicz