在 Flutter 1.12.1 版本ancestorInheritedElementForWidgetOfExactType被弃用之后。我们getElementForInheritedWidgetOfExactType现在应该使用。如何编辑它BlocProvider以使用这种新方法?
import 'package:flutter/material.dart';
Type _typeOf<T>() => T;
abstract class BlocBase {
void dispose();
}
class BlocProvider<T extends BlocBase> extends StatefulWidget {
BlocProvider({
Key key,
@required this.child,
@required this.bloc,
}) : super(key: key);
final Widget child;
final T bloc;
@override
_BlocProviderState<T> createState() => _BlocProviderState<T>();
static T of<T extends BlocBase>(BuildContext context) {
final type = _typeOf<_BlocProviderInherited<T>>();
_BlocProviderInherited<T> provider =
context.ancestorInheritedElementForWidgetOfExactType(type)?.widget; //deprecated
return provider?.bloc;
}
}
class _BlocProviderState<T extends BlocBase> extends State<BlocProvider<T>> {
@override …Run Code Online (Sandbox Code Playgroud) 我正在为具有 2 个项目(2 个 textViews)的列表视图创建一个数组适配器。
我知道如何将单个项目添加到我的适配器:
ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this,R.layout.newsrow, R.id.titleTextView,myArray);
list.setAdapter(listAdapter);
Run Code Online (Sandbox Code Playgroud)
但是我应该怎么做才能将第二个 textView(在我的应用程序中称为 contentTextView)添加到 listAdapter?