【发布时间】:2020-05-14 00:04:41
【问题描述】:
我有这个飞镖文件category_data.dart:
import 'package:flutter/material.dart';
final List categories = [
'Entertainment',
'Sports',
'Politics',
'Science',
'Technology',
'Travel'
];
/*
you can change your category here.
If you change, make sure you have changed in the admin panel.
Otherwise the app will show error.
*/
/*
if your change the defalut category, make sure your category item munber is equal to category colors item number.
Example: If you have 5 categories, then remove an color item in the category colors.
else if you have more than 6 categories, then you have to add color items in the category colors List down below.
*/
final List categoryColors = [
Colors.orange[200],
Colors.blue[200],
Colors.red[200],
Colors.pink[200],
Colors.purple[200],
Colors.blueGrey[400]
];
我想通过 intl 插件添加国际化。为此,我使用以下代码来获取文本的语言环境翻译:
AppLocalizations.of(context).categoryName
那么类别列表将如下:
import 'package:flutter/material.dart';
import 'package:news_app/generated/l10n.dart';
final List categories = [
AppLocalizations.of(context).entertainment,
AppLocalizations.of(context).sports,
AppLocalizations.of(context).politics,
AppLocalizations.of(context).science,
AppLocalizations.of(context).technology,
AppLocalizations.of(context).travel
];
但是这段代码给了我一个错误,因为我没有上下文:
Undefined name 'context'.
Try correcting the name to one that is defined, or defining the name
您如何获得使用国际化的上下文?我只在小部件的构建方法中看到了上下文。
【问题讨论】:
标签: flutter