nank1ro / flutter-shadcn-ui

shadcn-ui ported in Flutter. Awesome UI components for Flutter, fully customizable.
https://mariuti.com/shadcn-ui
MIT License
876 stars 54 forks source link

Flutter web build fails --tree-shake-icons for simple example #126

Open walsha2 opened 2 weeks ago

walsha2 commented 2 weeks ago

Full Working Example:

Can be found on my fork, in the web-tree-shake branch:

https://github.com/walsha2/flutter-shadcn-ui/tree/web-tree-shake/app

Steps to reproduce

Steps to create can be found bellow. Just a bare bones flutter create app with shadcn_ui add as a dependency and the MateiralApp converted to a ShadApp. No other changes to the canned flutter create app.

flutter create --platforms web app

cd app

flutter pub get
flutter build web --release --tree-shake-icons

Expected results

Build succeeds without error. I can get it to work with --no-tree-shake-icons, but that bloats the delivered assets and none of the icons are tree shaken.

Actual results

Target web_release_bundle failed: IconTreeShakerException: Invalid ConstFinder result. 
Expected "fontPackage" to be a String, "fontFamily" to be a String, and "codePoint" to be an int, got: 
{codePoint: 9658.0, fontFamily: null, fontPackage: null, matchTextDirection: false, fontFamilyFallback: null}.

To disable icon tree shaking, pass --no-tree-shake-icons to the requested flutter build command
#0      IconTreeShaker._parseConstFinderResult (package:flutter_tools/src/build_system/targets/icon_tree_shaker.dart:333:9)
...

shadcn_ui version

main

Platform

Web

Code sample

flutter build web --release --tree-shake-icons

Screenshots or Video

Screenshots / Video demonstration [Upload media here]

Logs

Logs ```console >>> flutter build web --release --tree-shake-icons Target web_release_bundle failed: IconTreeShakerException: Invalid ConstFinder result. Expected "fontPackage" to be a String, "fontFamily" to be a String, and "codePoint" to be an int, got: {codePoint: 9658.0, fontFamily: null, fontPackage: null, matchTextDirection: false, fontFamilyFallback: null}. To disable icon tree shaking, pass --no-tree-shake-icons to the requested flutter build command #0 IconTreeShaker._parseConstFinderResult (package:flutter_tools/src/build_system/targets/icon_tree_shaker.dart:333:9) #1 IconTreeShaker._findConstants (package:flutter_tools/src/build_system/targets/icon_tree_shaker.dart:321:12) #2 IconTreeShaker._getIconData (package:flutter_tools/src/build_system/targets/icon_tree_shaker.dart:109:45) #3 IconTreeShaker.subsetFont (package:flutter_tools/src/build_system/targets/icon_tree_shaker.dart:178:5) #4 copyAssets. (package:flutter_tools/src/build_system/targets/assets.dart:158:25) #5 Future.wait. (dart:async/future.dart:524:21) #6 copyAssets (package:flutter_tools/src/build_system/targets/assets.dart:126:3) #7 WebReleaseBundle.build (package:flutter_tools/src/build_system/targets/web.dart:450:29) #8 _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:875:9) #9 Future.wait. (dart:async/future.dart:524:21) #10 _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:813:32) #11 FlutterBuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:642:16) #12 WebBuilder.buildWeb (package:flutter_tools/src/web/compile.dart:92:34) #13 BuildWebCommand.runCommand (package:flutter_tools/src/commands/build_web.dart:230:5) #14 FlutterCommand.run. (package:flutter_tools/src/runner/flutter_command.dart:1394:27) #15 AppContext.run. (package:flutter_tools/src/base/context.dart:153:19) #16 CommandRunner.runCommand (package:args/command_runner.dart:212:13) #17 FlutterCommandRunner.runCommand. (package:flutter_tools/src/runner/flutter_command_runner.dart:372:9) #18 AppContext.run. (package:flutter_tools/src/base/context.dart:153:19) #19 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:308:5) #20 run.. (package:flutter_tools/runner.dart:130:9) #21 AppContext.run. (package:flutter_tools/src/base/context.dart:153:19) #22 main (package:flutter_tools/executable.dart:93:3) Compiling lib/main.dart for the Web... 1,089ms Error: Failed to compile application for the Web. ```

Flutter Doctor output

Doctor output ```console Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.22.3, on macOS 14.6.1 23G93 darwin-arm64, locale en-US) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 15.0.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.3) [✓] VS Code (version 1.92.2) [✓] Connected device (3 available) [✓] Network resources ```
nank1ro commented 2 weeks ago

I'm already aware of this bug. See https://github.com/flutter/flutter/issues/149267 They fixed it on master but the fix has no reached stable yet. You have two options for now:

This is just temporary, we need to wait a little bit for the fix to reach stable