wiredash-sdk icon indicating copy to clipboard operation
wiredash-sdk copied to clipboard

Crash on initializeDateFormatting

Open Prayer-RecycleSmart opened this issue 3 years ago • 4 comments

Describe the bug Adding DateFormat initialisation crash the app.

I have tested it with some of your examples and the result is the same. (e.g. wiredash-sdk/examples/localization/lib/main.dart) If I don't use date formatters everything works fine.

...
class _LocalizationExampleState extends State<LocalizationExample> {
  /// The locale that was selected by the user, defaults to the system locale
  Locale _selectedLocale = window.locale;

  @override
  void initState() {
    _setupDateFormatting();
    super.initState();
  }

  Future<void> _setupDateFormatting() async {
    await initializeDateFormatting('en');
  }

  @override
  Widget build(BuildContext context) {
    return Wiredash(
...

Stacktrace

#0      _UnmodifiableMapMixin.[]= (dart:collection/maps.dart:269:5)
#1      initializeDateFormattingCustom (package:intl/date_symbol_data_custom.dart:35:19)
#2      loadDateIntlDataIfNotLoaded.<anonymous closure>
(package:flutter_localizations/src/utils/date_localizations.dart:25:33)
#3      CastMap.forEach.<anonymous closure> (dart:_internal/cast.dart:288:8)
#4      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:614:13)
#5      CastMap.forEach (dart:_internal/cast.dart:287:13)
#6      loadDateIntlDataIfNotLoaded (package:flutter_localizations/src/utils/date_localizations.dart:21:8)
#7      _MaterialLocalizationsDelegate.load.<anonymous closure>
(package:flutter_localizations/src/material_localizations.dart:728:12)
#8      _LinkedHashMapMixin.putIfAbsent (dart:collection-patch/compact_hash.dart:524:23)
#9      _MaterialLocalizationsDelegate.load (package:flutter_localizations/src/material_localizations.dart:727:32)
#10     _loadAll (package:flutter/src/widgets/localizations.dart:55:49)
#11     _LocalizationsState.load (package:flutter/src/widgets/localizations.dart:532:62)
#12     _LocalizationsState.initState (package:flutter/src/widgets/localizations.dart:497:5)
#13     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4942:57)
#14     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4781:5)
...     Normal element mounting (228 frames)
#242    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3817:16)
#243    Element.updateChild (package:flutter/src/widgets/framework.dart:3551:18)
#244    RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1202:16)
#245    RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1171:5)
#246    RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure>
(package:flutter/src/widgets/binding.dart:1119:18)
#247    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2597:19)
#248    RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1118:13)
#249    WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:953:7)
#250    WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:933:7)
(elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)

Wiredash SDK Info 1.5.0

Flutter SDK 3.0.5

Prayer-RecycleSmart avatar Aug 30 '22 01:08 Prayer-RecycleSmart

Hey, I had a quick look and can confirm it's happening.

I only had a quick look but it might not be directly related to Wiredash. It seems like a bug of the MaterialLocalizations or the intl package itself.

Nonetheless, it's annoying and we should find a solution!

passsy avatar Aug 31 '22 05:08 passsy

This bug was already reported in Flutter https://github.com/flutter/flutter/issues/70040

passsy avatar Sep 01 '22 08:09 passsy

:) it hasn't been touched in the last 2 years... I will have to keep wiredash to 0.7 which is working fine

Prayer-RecycleSmart avatar Sep 01 '22 09:09 Prayer-RecycleSmart

There might be a simple solution.

Remove the initializeDateFormatting call and instead add localizationsDelegates to your MaterialApp. It will initialize DateFormat for you.

import 'package:flutter_localizations/flutter_localizations.dart';

MaterialApp(
  supportedLocales: [
    Locale('en'),
    Locale('de'),
    // .. whatever you support
  ],
  localizationsDelegates: [
    ...GlobalMaterialLocalizations.delegates,
  ],
)

passsy avatar Sep 02 '22 15:09 passsy

https://github.com/wiredashio/wiredash-sdk/issues/260 was able to resolve the issue with the solution above ☝️

passsy avatar Dec 10 '22 14:12 passsy