skip to Main Content

I have recently started a new Flutter project. There is very little to it at this point. Only a couple of files and some basic packages like riverpod and intl for localization.

Whenever I run flutter analyze on my local machine there are no problems on my current branch. This remains the same after flutter clean and flutter pub get etc.

However, when I commit and push on this branch to Gitlab the flutter analyze that I call in my CI does produce three issues which seem to be related to not being able to find or access the intl package.

Here is my Gitlab CI file:

analyse:
    stage: test
    image: "cirrusci/flutter:stable"
    before_script:
    - export PATH="$PATH":"$HOME/.flutter-sdk/.pub-cache/bin"
    - flutter pub get
    - flutter --version
    script:
        - flutter analyze

test:
    stage: test
    image: "cirrusci/flutter:stable"
    before_script:
    - export PATH="$PATH":"$HOME/.flutter-sdk/.pub-cache/bin"
    - flutter pub get
    script:
        - flutter test -j 1 test

The version call was to make sure the Flutter and Dart versions are the same in Gitlab and local which they are.

And here is the output of the analyze stage:

Running with gitlab-runner 15.9.0~beta.115.g598a7c91 (598a7c91)
  on blue-4.shared.runners-manager.gitlab.com/default J2nyww-s, system ID: s_5425356d8adf
  feature flags: FF_USE_IMPROVED_URL_MASKING:true
Resolving secrets 00:00
Preparing the "docker+machine" executor 01:21
Using Docker executor with image cirrusci/flutter:stable ...
Pulling docker image cirrusci/flutter:stable ...
Using docker image sha256:459db32a49bba36ef4fae0e61d91b27586b2e261bb03465b85da96b43fd46531 for cirrusci/flutter:stable with digest cirrusci/flutter@sha256:32e7d16c7e1458d3135e945ceec82c5d43bfda289526f850711f3908fb927502 ...
Preparing environment 00:02
Running on runner-j2nyww-s-project-43681222-concurrent-0 via runner-j2nyww-s-shared-1678886240-62a8435b...
Getting source from Git repository 00:03
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/saxion.nl/aad/hybrid/assignment2-framework1/17/.git/
Created fresh repository.
Checking out 4a9dcab0 as detached HEAD (ref is Outline_creation)...
Skipping Git submodules setup
Executing "step_script" stage of the job script 00:33
Using docker image sha256:459db32a49bba36ef4fae0e61d91b27586b2e261bb03465b85da96b43fd46531 for cirrusci/flutter:stable with digest cirrusci/flutter@sha256:32e7d16c7e1458d3135e945ceec82c5d43bfda289526f850711f3908fb927502 ...
$ flutter clean
$ flutter pub get
Running "flutter pub get" in 17...
Resolving dependencies...
  async 2.10.0 (2.11.0 available)
  build_daemon 3.1.1 (4.0.0 available)
  build_runner 2.3.3 (2.4.1 available)
  characters 1.2.1 (1.3.0 available)
  collection 1.17.0 (1.17.1 available)
  intl 0.17.0 (0.18.0 available)
  js 0.6.5 (0.6.7 available)
  matcher 0.12.13 (0.12.14 available)
  material_color_utilities 0.2.0 (0.3.0 available)
  meta 1.8.0 (1.9.0 available)
  path 1.8.2 (1.8.3 available)
  test_api 0.4.16 (0.4.18 available)
Got dependencies!
$ flutter --version
Flutter 3.7.7 • channel unknown • unknown source
Framework • revision 2ad6cd72c0 (7 days ago) • 2023-03-08 09:41:59 -0800
Engine • revision 1837b5be5f
Tools • Dart 2.19.4 • DevTools 2.20.1
$ flutter analyze
Analyzing 17...                                                 
  error • Target of URI doesn't exist: 'l10n/l10n.dart' • lib/main.dart:6:8 • uri_does_not_exist
  error • The values in a const list literal must be constants • lib/main.dart:20:11 • non_constant_list_element
  error • Undefined name 'S' • lib/main.dart:20:11 • undefined_identifier
3 issues found. (ran in 16.6s)
Cleaning up project directory and file based variables 00:01
ERROR: Job failed: exit code 1

The issues all occur in the main file which looks like this:

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:kook_app/ui/app/app_page.dart';

import 'l10n/l10n.dart';

void main() {
  runApp(const KookApp());
}

class KookApp extends StatelessWidget {
  const KookApp({super.key});

  @override
  Widget build(BuildContext context) {
    return ProviderScope(
      child: MaterialApp(
        localizationsDelegates: const [
          S.delegate,
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate,
        ],
        supportedLocales: const [
          Locale('en', 'UK'),
          Locale('nl'),
        ],
        debugShowCheckedModeBanner: false,
        title: 'KookApp',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: const AppPage(),
      ),
    );
  }
}

The file itself also does not report any issues in Android Studio.

Finally, for completion sake here are my pubspec:

name: kook_app
description: A new Flutter project.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
  sdk: '>=2.19.2 <3.0.0'

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  intl: 0.17.0
  cupertino_icons: ^1.0.2
  flutter_riverpod: ^2.3.2

dev_dependencies:
  flutter_test:
    sdk: flutter
  build_runner: any
  flutter_lints: ^2.0.0

flutter_intl:
  enabled: true
  arb_dir: lib/l10n/locales
  output_dir: lib/l10n

flutter:
  generate: true
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg

and analysis_options:

include: package:flutter_lints/flutter.yaml

linter:
  rules:
    always_put_required_named_parameters_first: true
    prefer_single_quotes: true

2

Answers


  1. Chosen as BEST ANSWER

    I'll put the answer here for if anyone needs it. Courtesy of @Albert221.

    Some of the generated files from the package were put into the git ignore resulting in the issue. I have removed them and everything works fine and dandy.


  2. The errors you receive:

      error • Target of URI doesn't exist: 'l10n/l10n.dart' • lib/main.dart:6:8 • uri_does_not_exist
      error • The values in a const list literal must be constants • lib/main.dart:20:11 • non_constant_list_element
      error • Undefined name 'S' • lib/main.dart:20:11 • undefined_identifier
    

    are here because the l10n/l10n.dart file does not exist.

    My guess is that you have this file, or the l10n/ directory in your .gitignore, so it’s not in the repository and the GitLab CI doesn’t clone it.

    You have two options:

    • if you still intend to not keep the l10n in your repository, you need to run flutter gen-l10n in your before_script,
    • or remove the l10n directory/file from your .gitignore and commit it to the repository.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search