Search code examples
flutterdartevalcode-push

CompileError: Cannot find import 'dart:ui' with flutter_eval


I've set up flutter_eval in my Flutter project, but when I try to compile the .evc file of

import 'package:eval_annotation/eval_annotation.dart';
import 'package:flutter/material.dart';

@RuntimeOverride('#myHomePage')
Widget myHomePageUpdate(BuildContext context) {
  final elements = List.generate(10, (index) => Text('Number: $index'));
  return Scaffold(
    appBar: AppBar(title: const Text('Home Page')),
    body: Column(children: elements),
  );
}

with

dart_eval compile -o update.evc

But I get the following error:

Loading files...
Adding packages from package config:
async boolean_selector characters clock collection eval_annotation fake_async flutter_lints lints matcher material_color_utilities meta path source_span stack_trace stream_channel string_scanner term_glyph test_api vector_math web sky_engine flutter flutter_test 

Compiling package hot_part...
Unhandled exception:
CompileError: Cannot find import 'dart:ui' (while parsing 'package:hot_part/hot_part.dart') at unknown
#0      _resolveImportsAndExports.<anonymous closure> (package:dart_eval/src/eval/compiler/compiler.dart:969:16)
#1      MappedListIterable.elementAt (dart:_internal/iterable.dart:425:31)
#2      ListIterable.toSet (dart:_internal/iterable.dart:229:18)
#3      _resolveImportsAndExports (package:dart_eval/src/eval/compiler/compiler.dart:971:12)
#4      Compiler.compileSources (package:dart_eval/src/eval/compiler/compiler.dart:322:33)
#5      Compiler.compile (package:dart_eval/src/eval/compiler/compiler.dart:164:12)
#6      cliCompile (package:dart_eval/src/eval/cli/compile.dart:126:34)
#7      main (file:[REDACTED]:71:5)
#8      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:33)
#9      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Solution

  • The hot-swappable package is missing Flutter framework bindings, which makes the compiler unable to create packaged code.

    Head over to the releases page of flutter_eval project to fetch the flutter_eval.json file matching your current flutter_eval version. Put the file in the package's directory .dart_eval/bindings like so:

    lib/
    pubspec.yaml
    ...
    .dart_eval/
      bindings/
        flutter_eval.json