aloisdeniel / flutter_device_preview

Approximate how your app looks and performs on another device.
https://aloisdeniel.github.io/flutter_device_preview/
MIT License
2.2k stars 339 forks source link

Unsupported operation: Cannot set value in unmodifiable Map #67

Open riccardocalligaro opened 4 years ago

riccardocalligaro commented 4 years ago

Version: 0.4.8

Stacktrace

flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following UnsupportedError was thrown building DevicePreviewTheme:
flutter: Unsupported operation: Cannot set value in unmodifiable Map    
flutter:                                                                
flutter: The relevant error-causing widget was:                         
flutter:   DevicePreviewTheme                                           
flutter:   file:///Users/riccardo/Documents/dev/flutter/.pub-cache/hosted/pub.dartlang.org/device_preview-0.4.8/lib/src/device_preview.dart:451:12
flutter:                                                                
flutter: When the exception was thrown, this was the stack:             
flutter: #0      _ImmutableMap.[]= (dart:core-patch/immutable_map.dart:74:5)
flutter: #1      initializeDateFormattingCustom (package:intl/date_symbol_data_custom.dart:35:19)
flutter: #2      loadDateIntlDataIfNotLoaded.<anonymous closure> (package:flutter_localizations/src/utils/date_localizations.dart:43:9)
flutter: #3      CastMap.forEach.<anonymous closure> (dart:_internal/cast.dart:288:8)
flutter: #4      _ImmutableMap.forEach (dart:core-patch/immutable_map.dart:43:8)
flutter: #5      CastMap.forEach (dart:_internal/cast.dart:287:13)      
flutter: #6      loadDateIntlDataIfNotLoaded (package:flutter_localizations/src/utils/date_localizations.dart:26:8)
flutter: #7      _GlobalCupertinoLocalizationsDelegate.load.<anonymous closure> (package:flutter_localizations/src/cupertino_localizations.dart:411:7)
flutter: #8      _LinkedHashMapMixin.putIfAbsent (dart:collection-patch/compact_hash.dart:291:23)
flutter: #9      _GlobalCupertinoLocalizationsDelegate.load (package:flutter_localizations/src/cupertino_localizations.dart:410:32)
flutter: #10     _loadAll (package:flutter/src/widgets/localizations.dart:60:49)
flutter: #11     _LocalizationsState.load (package:flutter/src/widgets/localizations.dart:515:62)
flutter: #12     _LocalizationsState.initState (package:flutter/src/widgets/localizations.dart:480:5)
flutter: #13     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4684:58)
flutter: #14     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
flutter: ...     Normal element mounting (15 frames)                    
flutter: #29     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
flutter: #30     Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
flutter: #31     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
flutter: #32     _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:397:11)
flutter: #33     Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
flutter: #34     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
flutter: #35     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #42     SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #49     SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #56     _NestedHookElement.mount (package:nested/nested.dart:188:11)
flutter: #57     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
flutter: #58     Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
flutter: #59     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
flutter: #60     _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:397:11)
flutter: #61     Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
flutter: #62     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
flutter: #63     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #70     SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #77     SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #84     _NestedHookElement.mount (package:nested/nested.dart:188:11)
flutter: #85     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
flutter: #86     Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
flutter: #87     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
flutter: #88     _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:397:11)
flutter: #89     Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
flutter: #90     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
flutter: #91     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #98     SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #105    SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #112    _NestedHookElement.mount (package:nested/nested.dart:188:11)
flutter: #113    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
flutter: #114    Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
flutter: #115    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
flutter: #116    _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:397:11)
flutter: #117    Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
flutter: #118    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
flutter: #119    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #126    SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #133    SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #140    _NestedHookElement.mount (package:nested/nested.dart:188:11)
flutter: #141    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
flutter: #142    Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
flutter: #143    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
flutter: #144    _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:397:11)
flutter: #145    Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
flutter: #146    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
flutter: #147    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #154    SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #161    SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #168    _NestedHookElement.mount (package:nested/nested.dart:188:11)
flutter: #169    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
flutter: #170    Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
flutter: #171    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
flutter: #172    _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:397:11)
flutter: #173    Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
flutter: #174    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
flutter: #175    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #182    SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #189    SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #196    _NestedHookElement.mount (package:nested/nested.dart:188:11)
flutter: #197    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
flutter: #198    Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
flutter: #199    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
flutter: #200    _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:397:11)
flutter: #201    Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
flutter: #202    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
flutter: #203    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #210    SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #217    SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #224    _NestedHookElement.mount (package:nested/nested.dart:188:11)
flutter: #225    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
flutter: #226    Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
flutter: #227    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
flutter: #228    _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:397:11)
flutter: #229    Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
flutter: #230    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
flutter: #231    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #238    SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #245    SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #252    _NestedHookElement.mount (package:nested/nested.dart:188:11)
flutter: #253    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
flutter: #254    Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
flutter: #255    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
flutter: #256    _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:397:11)
flutter: #257    Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
flutter: #258    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
flutter: #259    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #266    SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #273    SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #280    _NestedHookElement.mount (package:nested/nested.dart:188:11)
flutter: #281    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
flutter: #282    Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
flutter: #283    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
flutter: #284    _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:397:11)
flutter: #285    Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
flutter: #286    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
flutter: #287    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #294    SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #301    SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #308    _NestedHookElement.mount (package:nested/nested.dart:188:11)
flutter: #309    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
flutter: #310    Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
flutter: #311    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
flutter: #312    _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:397:11)
flutter: #313    Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
flutter: #314    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
flutter: #315    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #322    SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
flutter: ...     Normal element mounting (7 frames)                     
flutter: #329    SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)

Flutter doctor


[✓] Flutter (Channel stable, 1.20.2, on Mac OS X 10.15.6 19G2021, locale it)
    • Flutter version 1.20.2 at /Users/riccardo/Documents/dev/flutter
    • Framework revision bbfbf1770c (3 weeks ago), 2020-08-13 08:33:09 -0700
    • Engine revision 9d5b21729f
    • Dart version 2.9.1

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/riccardo/Library/Android/sdk
    • Platform android-30, build-tools 30.0.2
    • 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.6)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.6, Build version 11E708
    • CocoaPods version 1.9.3

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

[!] IntelliJ IDEA Ultimate Edition (version 2020.2.1)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • For information about installing plugins, see
      https://flutter.dev/intellij-setup/#installing-the-plugins

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

[✓] Connected device (2 available)
    • Riccardo’s iPhone (mobile)          • 7ceb041f57ded9b45154920a30156b5b5146648b • ios • iOS
      13.2
    • iPhone SE (2nd generation) (mobile) • 585BBD64-C65E-4FB4-AD9F-5B58D8636C23     • ios •
      com.apple.CoreSimulator.SimRuntime.iOS-13-6 (simulator)```
aloisdeniel commented 4 years ago

Can you try the prerelease ?

Since I updated the way the tree behaves, it may be better now.

makstheimba commented 4 years ago

Same issue for me. Tried prerelease version but it falis with:

../../../../../../.pub-cache/hosted/pub.dartlang.org/device_preview-0.5.0-prerelease.4/lib/src/tool_bar/format.dart:4:8: Error: Error when reading '../../../../../../.pub-cache/hosted/pub.dartlang.org/meta-1.1.8/lib/meta_meta.dart': No such file or directory
import 'package:meta/meta_meta.dart';
       ^
../../../../../../.pub-cache/hosted/pub.dartlang.org/device_preview-0.5.0-prerelease.4/lib/src/tool_bar/menus/devices.dart:157:25: Error: Getter not found: 'phonelink_setup_outlined'.
            icon: Icons.phonelink_setup_outlined,
                        ^^^^^^^^^^^^^^^^^^^^^^^^
aloisdeniel commented 4 years ago

It seems like an environment problem on your side.

Which version of flutter do you use ? Can you run a flutter clean ?

(I published a new prerelease version).

makstheimba commented 4 years ago

@aloisdeniel I experimented a bit more and fount out what caused this error. Before running the app we initialized date formatting with initializeDateFormatting('ru_RU').then((_) => runApp(...) from intl package. If I remove this line then your library works without an error. However I would still like to be able to use initializeDateFormatting 🤔

Using Flutter 1.22

UPD: I moved initializeDateFormatting('ru_RU') call into a builder of DevicePreview and it's all working now. I was a bit afraid that I should only start my app after initializeDateFormatting resolved it's Future, but turns out that this method is actually synchronous and only returns new Future.value(null) for some weird reason.

So this set up helped me fix the issue:

runApp(DevicePreview(
      enabled: !kReleaseMode,
      availablesLocales: [NamedLocale('ru', 'RU')],
      builder: (context) {
        initializeDateFormatting('ru_RU');
        return MyApp();
      }));
omar-alshyokh commented 3 years ago

Same issue for me. Tried prerelease version but it falis with:

../../../../../../.pub-cache/hosted/pub.dartlang.org/device_preview-0.5.0-prerelease.4/lib/src/tool_bar/format.dart:4:8: Error: Error when reading '../../../../../../.pub-cache/hosted/pub.dartlang.org/meta-1.1.8/lib/meta_meta.dart': No such file or directory
import 'package:meta/meta_meta.dart';
       ^
../../../../../../.pub-cache/hosted/pub.dartlang.org/device_preview-0.5.0-prerelease.4/lib/src/tool_bar/menus/devices.dart:157:25: Error: Getter not found: 'phonelink_setup_outlined'.
            icon: Icons.phonelink_setup_outlined,
                        ^^^^^^^^^^^^^^^^^^^^^^^^

same issues , any update please

msxenon commented 3 years ago

same issue

rednikisfun commented 3 years ago

Same issue

filly82 commented 2 years ago

got the same error. found out that it only occurs when I'm using this method here from the "intl"-package somewhere in my code (directly or any package that uses it): initializeDateFormatting('de_DE'); and I need to use this method when working with non-english Locales (in my case for formatting dates)

and the initiator of this issue @riccardocalligaro is also using the "intl" package, so it seems that it's the same problem

This is the Stacktrace i get:

The following UnsupportedError was thrown building Positioned(left: 0.0, top: 0.0, right: 0.0, bottom: 0.0):
Unsupported operation: Cannot modify unmodifiable map

The relevant error-causing widget was: 
  Positioned Positioned:file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/device_preview-1.0.0/lib/src/device_preview.dart:599:36
When the exception was thrown, this was the stack: 
#0      _UnmodifiableMapMixin.[]= (dart:collection/maps.dart:269:5)
#1      initializeDateFormattingCustom (package:intl/date_symbol_data_custom.dart:35:19)

and this is the most basic example for reproduction:

import 'package:device_preview/device_preview.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';

void main() => runApp(
  DevicePreview(
    enabled: !kReleaseMode,
    builder: (context) => MyApp(), // Wrap your app
  ),
);

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    initializeDateFormatting('de_DE');
    return MaterialApp(
      useInheritedMediaQuery: true,
      locale: DevicePreview.locale(context),
      builder: DevicePreview.appBuilder,
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
          child: Column(
            children: [
              Text('${DateFormat('E, dd.MM.yyyy', 'en_US').format(DateTime.now())}'),
              Text('${DateFormat('E, dd.MM.yyyy', 'de_DE').format(DateTime.now())}')
            ],
          ),
      ),
    );
  }
}

@aloisdeniel is that something you can fix on your side?

sawirricardo commented 2 years ago

I am still facing this issue using the current 1.0.0 . How did you guys fixed this?

filly82 commented 2 years ago

by not using the 'intl' package

sawirricardo commented 2 years ago

@filly82 but then how do you configure the intl package?

filly82 commented 2 years ago

when you don't use it then you don't need to configure it :)

in my case it was following method that caused the problem, so I don't use it anymore initializeDateFormatting(); in your case it could be another method from the package that is causing the error.

filly82 commented 2 years ago

@sawirricardo look at @makstheimba post for a temporary fix if you are using the intl-package directly

in my case that is not possible, because i am not using the package directly, I use another package that uses the intl-package

sawirricardo commented 2 years ago

@filly82 , I used it directly, though. But it's true that if I take out the initializeDateFormatting(), the app compiles successfully. But, it seems not a good fix.

filly82 commented 2 years ago

@sawirricardo Have you read the post from @makstheimba completely? No need to take the method out, you have to relocate it

sawirricardo commented 2 years ago

@filly82 Done that, but no luck. It still errs due to either "directionality" widget or Positioned widget. Both of them under error Unsupported operation: Cannot set value in unmodifiable Map.

m66are commented 2 years ago

Removing the initializeDateFormatting fixed the problem in my case

jordanparrott96 commented 2 years ago

I'm still encountering this issue. The fix from @makstheimba worked for the time being.

Kalffman commented 1 year ago

Same issue here. Exaclty what described before. Using Intl package throw that error. Any updates?