Dropsource / monarch

Monarch is a tool for building Flutter widgets in isolation. It makes it easy to build, test and debug complex UIs.
https://monarchapp.io
MIT License
433 stars 22 forks source link

GoogleFonts in theme definition generates exceptions #89

Open philipmjohnson opened 1 year ago

philipmjohnson commented 1 year ago

I have a custom theme defined as follows:

@MonarchTheme('Green Forest: Light', isDefault: true)
ThemeData get greenForestLight => FlexThemeData.light(
      scheme: FlexScheme.green,
      surfaceMode: FlexSurfaceMode.levelSurfacesLowScaffold,
      blendLevel: 7,
      subThemesData: const FlexSubThemesData(
        blendOnLevel: 10,
        blendOnColors: false,
        useTextTheme: true,
      ),
      visualDensity: FlexColorScheme.comfortablePlatformDensity,
      fontFamily: GoogleFonts.notoSans().fontFamily,
    );

When I run monarch, the following error messages appear in the console:

$ monarch run --reload hot-restart
Using flutter sdk at /Users/philipjohnson/flutter/bin/flutter
Enabling Flutter for desktop

Starting Monarch.

Preparing stories...
3.1sec elapsed, 0/2 tasks completed
6.2sec elapsed, 0/2 tasks completed
9.3sec elapsed, 0/2 tasks completed
12.4sec elapsed, 0/2 tasks completed
15.5sec elapsed, 1/2 tasks completed
Preparing stories completed, took 18.3sec.

Launching Monarch app...
3.1sec elapsed, 0/1 tasks completed
Launching Monarch app completed, took 3.5sec.

Attaching to stories...
══╡ EXCEPTION CAUGHT BY MONARCH ╞═══════════════════════════════════════════════════════════════════
The following message was thrown while a story was not selected
PlatformException(channel-error, Unable to establish connection on channel., null, null)

There was no active story selected.

When the exception was thrown, this was the stack:
package:path_provider_foundation/messages.g.dart 39:7                       PathProviderApi.getDirectoryPath
===== asynchronous gap ===========================
dart:async                                                                  _CustomZone.registerBinaryCallback
package:google_fonts/src/file_io_desktop_and_mobile.dart 15:16              saveFontToDeviceFileSystem
package:google_fonts/src/google_fonts_base.dart 265:24                      _httpFetchFontAndSaveToDevice
===== asynchronous gap ===========================
dart:async                                                                  _CustomZone.registerUnaryCallback
package:google_fonts/src/google_fonts_base.dart 254:16                      _httpFetchFontAndSaveToDevice
package:google_fonts/src/google_fonts_base.dart 169:18                      loadFontIfNecessary
===== asynchronous gap ===========================
dart:async                                                                  _CustomZone.registerUnaryCallback
package:google_fonts/src/google_fonts_base.dart 145:31                      loadFontIfNecessary
package:google_fonts/src/google_fonts_base.dart 110:3                       googleFontsTextStyle
package:google_fonts/google_fonts.dart 94297:12                             GoogleFonts.notoSans
package:ggc_app/theme_data.dart 20:31                                       greenForestLight
.dart_tool/build/generated/ggc_app/lib/theme_data.meta_themes.g.dart 11:45  metaThemeItems
.dart_tool/build/generated/ggc_app/lib/main_monarch.g.dart 17:13            _projectData
.dart_tool/build/generated/ggc_app/lib/main_monarch.g.dart 24:29            main.<fn>
package:monarch/src/preview/project_data_manager.dart 16:23                 ProjectDataManager.load
package:monarch/src/preview/start_monarch_preview.dart 32:22                _startMonarchPreview
package:monarch/src/preview/start_monarch_preview.dart 23:5                 startMonarchPreview.<fn>
package:stack_trace                                                         Chain.capture
package:monarch/src/preview/start_monarch_preview.dart 22:9                 startMonarchPreview
.dart_tool/build/generated/ggc_app/lib/main_monarch.g.dart 24:3             main

════════════════════════════════════════════════════════════════════════════════════════════════════

3.1sec elapsed
6.2sec elapsed
9.3sec elapsed
Attaching to stories completed, took 12.4sec.

Setting up stories watch...
Setting up stories watch completed, took 2.8sec.

Monarch key commands:
r Hot reload.
R Hot restart (default).
h Show this list of commands.
⌃C Quit.

If I comment out fontFamily: GoogleFonts.notoSans().fontFamily, in my theme definition, the error messages go away.

My pubspec.yml:

name: ggc_app
description: Geo Garden Club app
publish_to: 'none'
version: 1.0.0+1
environment:
  sdk: '>=2.18.4 <3.0.0'
dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  # Theme stuff
  flutter_native_splash: ^2.2.14
  flex_color_scheme: ^7.0.3
  badges: ^3.0.3
  flutter_markdown: ^0.6.13
  # The next three provide forms.
  flutter_form_builder: ^7.7.0
  form_builder_validators: ^8.4.0
  intl: ^0.17.0
  # State management
  flutter_riverpod: ^2.0.2
  # Firebase
  firebase_core: ^2.4.1
  firebase_auth: ^4.2.10
  cloud_firestore: ^4.3.1
  firebase_ui_auth: ^1.1.7
  logger: ^1.1.0
  freezed_annotation: ^2.2.0
  json_annotation: ^4.8.0
  cached_network_image: ^3.2.3
  go_router: ^6.5.5
  google_fonts: ^4.0.3
  monarch_annotations: ^1.0.2

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.0
  build_runner: ^2.1.11
  freezed: ^2.3.2
  json_serializable: ^6.6.1
  monarch: ^3.0.0
  flutter_gen: ^5.3.0

flutter_native_splash:
  image: assets/images/ggc.png
  color: "#43b02a"

flutter:
  uses-material-design: true
  # Enable generation of localized Strings from arb files.
  generate: true
  assets:
    - assets/images/
    - assets/initialData/
    - assets/monarchData/

Results of running flutter doctor:

$ flutter doctor                                                                    11:44:20
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.7.11, on macOS 13.2.1 22D68 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

• No issues found!
fertrig commented 1 year ago

I was able to reproduce. I also got it to work on my local by building monarch_macos with the path_provider plugin.

Screen Shot 2023-04-25 at 7 21 34 PM

There are two options for you:

  1. I can give you instructions on how you can build monarch_macos yourself with the path_provider plugin. This will require some maintenance on your part.
  2. We are considering including the path_provider plugin (and other common plugins) in the monarch binaries. This would be part of a future release and it should be pretty seamless once it is out.

I'll keep this issue open until then.

fertrig commented 1 year ago

I forgot to mention: the exception you see means that the google font the code requested could not be saved to disk, thus the code defaults to a system font.

philipmjohnson commented 1 year ago

Thanks. I prefer the option of waiting for a future release at this point, so no need for instructions.

vimaxwell commented 10 months ago

I got similar error with CachedNetworkImage