我现在在我的项目中使用Ffltter Gallary,这是软件包参考:

import 'package:flutter_gen/gen_l10n/gallery_localizations.dart';

但它表明:

Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/gallery_localizations.dart'.

我在pubspec.yaml中添加了lib:

flutter_localizations:
    sdk: flutter
intl: ^0.16.1
flutter_localized_locales: ^1.1.1

并增加了l10n.yaml:

template-arb-file: intl_en.arb
output-localization-file: gallery_localizations.dart
output-class: GalleryLocalizations
preferred-supported-locales:
  - en
use-deferred-loading: false

我是不是遗漏了什么?还是不能工作,我应该怎么做才能使它工作呢?以下是完整的代码:

import 'package:flutter/material.dart';
import 'package:animations/animations.dart';
import 'package:flutter_gen/gen_l10n/gallery_localizations.dart';

enum BottomNavigationDemoType {
  withLabels,
  withoutLabels,
}

class BottomNavigationDemo extends StatefulWidget {
  const BottomNavigationDemo({Key key, @required this.type}) : super(key: key);

  final BottomNavigationDemoType type;

  @override
  _BottomNavigationDemoState createState() => _BottomNavigationDemoState();
}

class _BottomNavigationDemoState extends State<BottomNavigationDemo> {
  int _currentIndex = 0;

  String _title(BuildContext context) {
    switch (widget.type) {
      case BottomNavigationDemoType.withLabels:
        return GalleryLocalizations.of(context)
            .demoBottomNavigationPersistentLabels;
      case BottomNavigationDemoType.withoutLabels:
        return GalleryLocalizations.of(context)
            .demoBottomNavigationSelectedLabel;
    }
    return '';
  }

  @override
  Widget build(BuildContext context) {
    final colorScheme = Theme.of(context).colorScheme;
    final textTheme = Theme.of(context).textTheme;

    var bottomNavigationBarItems = <BottomNavigationBarItem>[
      BottomNavigationBarItem(
        icon: const Icon(Icons.add_comment),
        label: GalleryLocalizations.of(context).bottomNavigationCommentsTab,
      ),
      BottomNavigationBarItem(
        icon: const Icon(Icons.calendar_today),
        label: GalleryLocalizations.of(context).bottomNavigationCalendarTab,
      ),
      BottomNavigationBarItem(
        icon: const Icon(Icons.account_circle),
        label: GalleryLocalizations.of(context).bottomNavigationAccountTab,
      ),
      BottomNavigationBarItem(
        icon: const Icon(Icons.alarm_on),
        label: GalleryLocalizations.of(context).bottomNavigationAlarmTab,
      ),
      BottomNavigationBarItem(
        icon: const Icon(Icons.camera_enhance),
        label: GalleryLocalizations.of(context).bottomNavigationCameraTab,
      ),
    ];

    if (widget.type == BottomNavigationDemoType.withLabels) {
      bottomNavigationBarItems = bottomNavigationBarItems.sublist(
          0, bottomNavigationBarItems.length - 2);
      _currentIndex =
          _currentIndex.clamp(0, bottomNavigationBarItems.length - 1).toInt();
    }

    return Scaffold(
      appBar: AppBar(
        automaticallyImplyLeading: false,
        title: Text(_title(context)),
      ),
      body: Center(
        child: PageTransitionSwitcher(
          child: _NavigationDestinationView(
            // Adding [UniqueKey] to make sure the widget rebuilds when transitioning.
            key: UniqueKey(),
            item: bottomNavigationBarItems[_currentIndex],
          ),
          transitionBuilder: (child, animation, secondaryAnimation) {
            return FadeThroughTransition(
              child: child,
              animation: animation,
              secondaryAnimation: secondaryAnimation,
            );
          },
        ),
      ),
      bottomNavigationBar: BottomNavigationBar(
        showUnselectedLabels:
        widget.type == BottomNavigationDemoType.withLabels,
        items: bottomNavigationBarItems,
        currentIndex: _currentIndex,
        type: BottomNavigationBarType.fixed,
        selectedFontSize: textTheme.caption.fontSize,
        unselectedFontSize: textTheme.caption.fontSize,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
        selectedItemColor: colorScheme.onPrimary,
        unselectedItemColor: colorScheme.onPrimary.withOpacity(0.38),
        backgroundColor: colorScheme.primary,
      ),
    );
  }
}

class _NavigationDestinationView extends StatelessWidget {
  _NavigationDestinationView({Key key, this.item}) : super(key: key);

  final BottomNavigationBarItem item;

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        ExcludeSemantics(
          child: Center(
            child: Padding(
              padding: const EdgeInsets.all(16),
              child: ClipRRect(
                borderRadius: BorderRadius.circular(8),
                child: Image.asset(
                  'assets/demos/bottom_navigation_background.png',
                  package: 'flutter_gallery_assets',
                ),
              ),
            ),
          ),
        ),
        Center(
          child: IconTheme(
            data: const IconThemeData(
              color: Colors.white,
              size: 80,
            ),
            child: Semantics(
              label: GalleryLocalizations.of(context)
                  .bottomNavigationContentPlaceholder(
                item.label,
              ),
              child: item.icon,
            ),
          ),
        ),
      ],
    );
  }
}

当我运行命令flutter clean && flutter run 时,显示结果:

[dolphin@MiWiFi-R4CM-srv]~/AndroidStudioProjects/Cruise% flutter clean && flutter run 
Attempted to generate localizations code without having the flutter: generate flag turned on.
Check pubspec.yaml and ensure that flutter: generate: true has been added and rebuild the project. Otherwise, the localizations source code will not be
importable.
Generating synthetic localizations package has failed.

推荐答案

我将这两行代码添加到pubspec中,使导入工作正常.yaml文件:

cupertino_icons: ^0.1.3 
flutter_gallery: ^2.4.0+20400

第一行实际上替换了原始的CUBITIO-ICONS依赖关系,即版本1.0.0,而Flutter 库依赖关系需要不同的版本,即0.1.3.

然后用‘Ffltter Pub Get’更新导入

本网站here列出了所有可能的Flatter_gallery导入.

Flutter相关问答推荐

如何在Firebase项目中更改包名称和包ID

video_player在Android上返回401 Unauthorized with Bunny CDN

BaseInputfield和Textfield有什么不同?

播放特定持续时间Flutter 的音频

如何使 dart 函数变得通用?

Flutter 构建 Web 分段故障 - 无法启动事件处理程序线程

在 flutter 的列中使用 Expanded 时出现渲染 Flex 错误

如何给按钮的边框半径?

无法在 Flutter 项目中安装最新版本的 image_picker

如何动态获取任何小部件的像素?

Dart:未捕获错误:RangeError(索引):索引超出范围:索引应小于 7:7

「Flutter」错误:没有名为'kind'的命名参数

reactive_flutter_BLE - 应用找到设备但无法连接(并读取 BLE 数据)

如何防止键盘将内容向上推?

Flutter Bloc 使用 Cubit 监听流和emits 状态

我无法从 Cloud firestore 访问文档字段并在 statefulwidget 类中显示它

如何在 SingleChildScrollView 小部件中管理自定义小部件状态

无法列出 com.facebook.android:facebook-login -Facebook 登录问题的版本

Flutter Firestore 数据库排序最近 24 小时内最喜欢的文档

Flutter 将方法应用于静态变量