大家好,这是我的整个方法:
Future<void> init() async {
FirebaseAuth.instance.userChanges().listen((user) {
if (user != null) {
_loginState = ApplicationLoginState.loggedIn;
_guestBookSubscription = FirebaseFirestore.instance
.collection('guestbook')
.orderBy('timestamp', descending: true)
.limit(3)
.snapshots()
.listen((snapshot) {
_guestBookMessages = [];
snapshot.docs.forEach((document) {
_guestBookMessages.add(
GuestBookMessage(
name: document.data()['name'] as String,
message: document.data()['text'] as String,
),
);
});
notifyListeners();
});
} else {
_loginState = ApplicationLoginState.loggedOut;
_guestBookMessages = [];
_guestBookSubscription?.cancel();
}
notifyListeners();
});
}
Run Code Online (Sandbox Code Playgroud)
dart 抱怨的部分是:
snapshot.docs.forEach((document) {
_guestBookMessages.add(
GuestBookMessage(
name: document.data()['name'] as String,
message: document.data()['text'] as String,
),
);
});
Run Code Online (Sandbox Code Playgroud)
我怎样才能改变这个方法而不破坏整个功能?我只是在寻找一种让 dart 快乐的方法。我提前感谢您的帮助。
import 'package:flutter/material.dart';
class SignInPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Time Tracker'),
elevation: 5.0,
),
body: _buildContent(),
backgroundColor: Colors.amber[50],
);
}
Widget _buildContent() {
return Padding(
padding: EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text(
'Sing in',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 32.0,
fontWeight: FontWeight.w600,
),
),
SizedBox(height: 8.0),
ElevatedButton(
child: Text('Sing in with google'),
onPressed: () {},
style: ElevatedButton.styleFrom(
primary: Colors.purple[200],
onPrimary: Colors.black87,
elevation: 6.0,
shadowColor: Colors.yellow[200],
),
],
), …Run Code Online (Sandbox Code Playgroud) 问题是标题。我正在尝试构建 todoye 应用程序,正如您所看到的,回调被认为是 ValueChanged<bool?> 不是一个简单的函数,所以我无法将我的逻辑移动到另一个 statefullwidget 以减少我的应用程序中的重建,我尝试了不同的事情,但我得到了总是出错请帮忙。这是我的代码:
import 'package:flutter/material.dart';
class TaskTile extends StatefulWidget {
@override
_TaskTileState createState() => _TaskTileState();
}
class _TaskTileState extends State<TaskTile> {
bool isChecked = false;
void checkBoxCallBack(bool checkBoxState) {
setState(() {
isChecked = checkBoxState;
});
}
@override
Widget build(BuildContext context) {
return ListTile(
title: Text(
'finish up angla\'s course today',
style: TextStyle(
decoration: isChecked ? TextDecoration.lineThrough : null,
),
),
trailing: TaskCheckBox(
checkBoxState: isChecked,
toggleCheckBoxState: checkBoxCallBack,
),
);
}
}
class TaskCheckBox extends StatelessWidget {
final …Run Code Online (Sandbox Code Playgroud) 大家好,第一个错误在标题中,让我先展示代码:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:todoye_app_angela/models/task_data.dart';
class AddTaskScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
String newTaskTitle;
return Container(
color: Color(0xFF757575),
child: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.limeAccent[400],
borderRadius: BorderRadius.only(
topLeft: Radius.circular(60),
topRight: Radius.circular(60),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
'Add Task',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 30, color: Colors.brown[900]),
),
SizedBox(
height: 12,
),
TextField(
onChanged: (newText) {
newTaskTitle = newText;
},
autocorrect: false,
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.brown[800]!, …Run Code Online (Sandbox Code Playgroud) 实际的问题是我无法运行这个命令:firebase deploy --only firestore:indexes
正如您从这个链接中看到的: https: //codelabs.developers.google.com/codelabs/Friendlyeats-flutter/#12
我正在尝试通过我的 flutter 项目学习 firebase ..一般来说,我不理解这里的索引问题,如果您这样做,我将非常感谢您的努力...我添加了一个新终端,但仍然收到此错误...请帮我解决这个问题。