2
respostas

[Dúvida] Erro em importar dart:ui

Estou fazendo esse curso. Ao chegar nessa aula - 07 Utilizando serviços no Flutter - faço os procedimentos indicados e o código que o instrutor ensina.

Mas tenho esse erro como resultado:

[Running] dart "d:\Desktop\CURSOS\ALURA\Curso Flutter\Curso Flutter WebAPI\flutter_webapi_first_course-aula01\lib\tempCodeRunnerFile.dart" /C:/Users/profl/AppData/Local/Pub/Cache/hosted/pub.dev/google_fonts-3.0.1/lib/google_fonts.dart:7:8: Error: Dart library 'dart:ui' is not available on this platform. import 'dart:ui' as ui; ^ Context: The unavailable library 'dart:ui' is imported through these packages:

package:flutter_webapi_first_course => package:google_fonts => dart:ui
package:flutter_webapi_first_course => package:google_fonts => package:flutter => dart:ui
...

Detailed import paths for (some of) the these imports:

package:flutter_webapi_first_course/tempCodeRunnerFile.dart => package:google_fonts/google_fonts.dart => dart:ui
package:flutter_webapi_first_course/tempCodeRunnerFile.dart => package:google_fonts/google_fonts.dart => package:flutter/material.dart => 
package:flutter_webapi_first_course/tempCodeRunnerFile.dart => package:google_fonts/google_fonts.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/foundation.dart => package:flutter/src/foundation/key.dart => package:flutter/src/foundation/diagnostics.dart => dart:ui
...

/C:/Users/profl/AppData/Local/Pub/Cache/hosted/pub.dev/google_fonts-3.0.1/lib/src/google_fonts_base.dart:6:8: Error: Dart library 'dart:ui' is not available on this platform. import 'dart:ui'; ^ /C:/Users/profl/AppData/Local/Pub/Cache/hosted/pub.dev/google_fonts-3.0.1/lib/src/google_fonts_variant.dart:5:8: Error: Dart library 'dart:ui' is not available on this platform. import 'dart:ui'; ^ /C:/flutter/packages/flutter/lib/src/material/animated_icons.dart:9:8: Error: Dart library 'dart:ui' is not available on this platform. import 'dart:ui' as ui show Canvas, Paint, Path, lerpDouble; ^ /C:/flutter/packages/flutter/lib/src/material/app.dart:5:8: Error: Dart library 'dart:ui' is not available on this platform. import 'dart:ui' as ui; ^ /C:/flutter/packages/flutter/lib/src/material/app_bar_theme.dart:5:8: Error: Dart library 'dart:ui' is not available on this platform. import 'dart:ui' show lerpDouble; ^ /C:/flutter/packages/flutter/lib/src/material/arc.dart:6:8: Error: Dart library 'dart:ui' is not available on this platform. import 'dart:ui' show lerpDouble; ^ /C:/flutter/packages/flutter/lib/src/material/badge_theme.dart:5:8: Error: Dart library 'dart:ui' is not available on this platform. import 'dart:ui' show lerpDouble; ^ /C:/flutter/packages/flutter/lib/src/material/banner_theme.dart:5:8: Error: Dart library 'dart:ui' is not available on this platform. import 'dart:ui' show lerpDouble; ^

[Done] exited with code=254 in 15.462 seconds

*****apaguei uma parte do erro do meio onde ele repete várias vezes a mesma coisa para não ultrapassar o limite de caracteres.

Já reinstalei várias vezes o VScode, as extensões, as versões do dart e do flutter. Mas não consigo resolver.

Alguém poderia me ajudar?

2 respostas

E aí, Arthur!

Esse erro geralmente acontece quando tem alguma treta com as dependências no Flutter. Parece que o Google Fonts tá causando umas confusões. Vamos tentar algumas coisas:

  1. Limpa o Cache do Pub: No terminal, vai no diretório do teu projeto e digita:

    flutter pub cache repair
    
  2. Reinstala as Dependências: Roda esses comandos:

    flutter clean
    flutter pub get
    
  3. Versões Certas: Confere se as versões do Dart e do Flutter que você tá usando são compatíveis. Às vezes, versões incompatíveis podem dar nisso.

  4. Atualizações do Flutter: Pode ser que tenha uma atualização nova do Flutter. Dá uma conferida com:

    flutter upgrade
    
  5. Atualizações do VSCode: Certifica que tu tá usando a versão mais recente do VSCode. Às vezes, esses problemas são corrigidos com updates.

  6. Analisa as Dependências: Dá uma olhada no pubspec.yaml e vê se tem alguma dependência que tá conflitando com o 'dart:ui'.

Boa sorte, meu chapa! Tomara que essas dicas te ajudem a desbugar essa parada.

Oi, obrigado.

Tentei essas alternativas. Mas o problema ainda continua.

Apareceram alguns erros novos além desse.

Could not run phased build action using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-7.4-all.zip'. org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'android'. A problem occurred configuring root project 'android'. A problem occurred evaluating root project 'android'. A problem occurred configuring project ':app'. A problem occurred evaluating project ':app'. Failed to apply plugin 'com.android.internal.application'. Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8. You can try some of the following options:

  • changing the IDE settings.
  • changing the JAVA_HOME environment variable.
  • changing org.gradle.java.home in gradle.properties.

Could not run phased build action using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-8.1.1-bin.zip'. org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'android'. A problem occurred configuring root project 'android'. A problem occurred evaluating root project 'android'. A problem occurred configuring project ':app'. A problem occurred evaluating project ':app'. Failed to apply plugin 'com.android.internal.application'. Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8. You can try some of the following options:

  • changing the IDE settings.
  • changing the JAVA_HOME environment variable.
  • changing org.gradle.java.home in gradle.properties.

Don't invoke 'print' in production code. Try using a logging framework.