说我定义...
final DocumentSnapshot doc;
Run Code Online (Sandbox Code Playgroud)
变量doc可能为空,所以我使用问号和点...
print(widget.doc); // null
print(widget.doc == null); // true
print(widget.doc?.data['name']);
Run Code Online (Sandbox Code Playgroud)
为什么widget.doc?.data['name']抛出错误Tried calling: []("name")而不是返回null?
我的理解?.是检查null它是否以及是否会返回null
我正在尝试使用 ListView.builder 显示一些卡片
我想将每张卡片的高度自动设置为其子内容的高度
class HomePage extends StatelessWidget {
Widget _buildListItems(BuildContext context, DocumentSnapshot document) {
return Center(
child: Card(
child: Column(
children: <Widget>[
ListTile(
title: Text(document['title']),
subtitle: Text(document['subtitle']),
),
Expanded(
child: Container(
padding: EdgeInsets.all(20.0),
child: Text(
document['summary'],
softWrap: true,
),
),
)
],
),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Title'),
centerTitle: true,
),
body: StreamBuilder(
stream: Firestore.instance.collection('randomDB').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return const Text('Loading...');
return ListView.builder(
itemExtent: 225.0,
itemCount: snapshot.data.documents.length, …Run Code Online (Sandbox Code Playgroud) 我正在使用颤振,我试图从我之前设置的 shared_preferences 中获取一个值,并将其显示在文本小部件中。但我得到 Instance ofFuture<String>而不是值。这是我的代码:
Future<String> getPhone() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
final String patientPhone = prefs.getString('patientPhone').toString();
print(patientPhone);
return patientPhone;
}
Future<String> phoneOfPatient = getPhone();
Center(child: Text('${phoneOfPatient}'),))
Run Code Online (Sandbox Code Playgroud) 我正在尝试集成firebase_crashlytics到我的 Flutter 应用程序中。
https://pub.dartlang.org/packages/firebase_crashlytics#-readme-tab-
我遇到了 iOS 集成问题。在文档中,指定的是If on Xcode 10 Add your app's built Info.plist location to the Build Phase's Input Files field. Eg: $(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)
我已经创建了 Firebase 项目并完成了 iOS 部分所需的初始设置,例如 Firebase 的 pod install 并在 AppDelegate 文件中添加代码。
我无法弄清楚这是什么意思?这是否意味着info.plist文件的文字路径。我下载了文档中提到的示例项目,但它与上述内容没有任何关系。我做了如下的事情

我从字面上将路径添加到我的info.plist文件中,如下所示$(BUILT_PRODUCTS_DIR)/$(/Users/priitshsawant/Desktop/firebase_crashltics/firebase_crashltics/ios/Runner/Info.plist)。我尝试使我的应用程序崩溃,但它没有出现在 Firebase Crashlytics 中
有什么方法可以创建带有圆形边框的自定义弹出窗口?这是我当前的代码和设计:
child: Container(
child: PopupMenuButton(
onSelected: _savedLocationOptionSelected,
itemBuilder: (context) {
return SavedLocationOptions.choises.map((value) {
return PopupMenuItem<String>(
value: value,
child: Text(value),
);
}).toList();
},
icon: Icon(
Icons.more_vert,
color: Colors.grey[300],
),
),
),
Run Code Online (Sandbox Code Playgroud)
我想在用户访问我的应用时向他们打招呼
我曾尝试使用 TimeOfDay 但它不起作用。
TimeOfDay now = TimeOfDay.now();
greetings(String greeting){
var greeting = now;
if(greeting <= '11: 59'){
return 'Morning';
} else if (greeting > '11:59' && <= '16:59'){
return 'Afternoon';
} else if (greeting > '16:59' && <= '23:59'){
return 'Afternoon';
} else {
return 'Morning';
}
}
Run Code Online (Sandbox Code Playgroud) 如果我将变量声明为最终变量,那么我想更改(按下时)的值(变量)就在其中,setState(){}以便可以更改这些变量,该怎么做才能防止这种情况发生?
还有,为什么这么写widget.value?
我试过用 static 而不是 final 不起作用
class BottomCard extends StatefulWidget {
String title;
int value;
@override
_BottomCardState createState() => _BottomCardState(); }
class _BottomCardState extends State<BottomCard> {.....
....<Widget>[
FloatingActionButton(
elevation: 0,
child: Icon(FontAwesomeIcons.plus),
onPressed: () {
setState(() {
widget.value++;
});
},
backgroundColor: Color(0xFF47535E),
),
Run Code Online (Sandbox Code Playgroud) 我的应用程序编译成功,直到 Flutter 版本升级。我收到以下错误:
Runner.app/Info.plist does not exist. The Flutter "Thin Binary" build phase must run after "Copy Bundle Resources".
Run Code Online (Sandbox Code Playgroud)
颤振医生 -v
[?] Flutter (Channel stable, 1.22.3, on Mac OS X 10.15.6 19G2021, locale fr-FR)
• Flutter version 1.22.3 at /Users/xxx/development/flutter
• Framework revision 8874f21e79 (3 days ago), 2020-10-29 14:14:35 -0700
• Engine revision a1440ca392
• Dart version 2.10.3
[?] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/xxx/Library/Android/sdk
• Platform android-R, build-tools 29.0.2 …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,它非常简单,但我不断收到此错误:
pub get failed(服务器不可用)——尝试在 1 秒内重试 1... 因为 bascis 依赖于任何不存在的 sdk 中的 integration_test(在 Flutter SDK 中找不到包 integration_test),版本求解失败。
我试过了
Pup 升级,Pub 获得。
我怎样才能摆脱这个错误?
我无法删除 TextField 的阴影和背景,这是我的代码:
TextFormField(
decoration: InputDecoration.collapsed(),
validator: (input) =>
input == "" ? 'The task is empty' : null,
onSaved: (input) => task = input,
)
Run Code Online (Sandbox Code Playgroud)
这是我想要的结果
我总是尝试 BoxDecoration 但没有成功,因为不与 TextFormField 兼容。