主镖
我想在卡片上循环播放。由于在Angular 2中,* ngFor现在可以以相同的方式正常工作,如何循环播放。我没有在卡片网上找到文档。您将在屏幕快照中找到输出。请帮助我了解如何循环显示卡或任何其他小部件
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
home:new MyCard()
);
}
}
class MyCard extends StatelessWidget{
@override
Widget build(BuildContext context) {
Widget allcards;
return new Scaffold(
appBar: new AppBar(
title: new Text('My First App'),
backgroundColor:new Color(0xFF673AB7),
),
body: new Container(
child: new Column(
children: <Widget>[
new Card(
child: new Column(
children: <Widget>[
new Image.network('https://i.ytimg.com/vi/fq4N0hgOWzU/maxresdefault.jpg'),
new Padding(
padding: new EdgeInsets.all(7.0),
child: new …Run Code Online (Sandbox Code Playgroud) 我是 Flutter 的新手,刚刚从阅读有关 Flutter 的教程中听说了 BLoC 概念。从本教程中,我第一次听说 BLoC。但是我在这篇文章中也看到了一个名为“Repository”的文件。基本上数据流是这样的:
Web API --> Api Provider --> Repository --> BLoC --> Widget
Run Code Online (Sandbox Code Playgroud)
我不明白的是,为什么需要 Repository 层,因为当我查看存储库文件时,它基本上只是返回 API Provider 的 Future 结果?我很好奇并尝试进一步搜索,我看到互联网上一些人的编码模式也有一个 Repository 层。
在原始文章中,API Provider 做了一切。它调用 get 请求,等待 Future 解析,将 JSON 数据转换为适当的模型,并返回用 Future 括起来的模型。
class ApiProvider {
Future<ItemModel> fetchMovieList() async {
final response = await client.get("http://api.themoviedb.org/3/movie/popular?api_key=$_apiKey");
if (response.statusCode == 200)
return ItemModel.fromJson(json.decode(response.body));
else
throw Exception('Failed to load post');
}
}
class Repository {
ApiProvider _api = ApiProvider();
Future<ItemModel> fetchMovieList() => _api.fetchMovieList(); // …Run Code Online (Sandbox Code Playgroud) 我制作了一个具有比例过渡的容器,它从 0 高度和宽度增长到 90 高度和宽度。
现在,我想做的是它应该随着它的增长而慢慢淡出。我需要为不透明度创建另一个动画控制器吗?最好的方法是什么?有人可以帮忙吗?
我的代码看起来像这样
import 'package:flutter/animation.dart';
import 'package:flutter/material.dart';
void main() => runApp(new MyAnimationApp());
class MyAnimationApp extends StatefulWidget {
@override
_MyAnimationAppState createState() => _MyAnimationAppState();
}
class _MyAnimationAppState extends State<MyAnimationApp>
with TickerProviderStateMixin {
Animation<double> animation;
AnimationController _controller;
@override
void initState() {
super.initState();
_controller =
new AnimationController(vsync: this, duration: Duration(seconds: 3))
..repeat();
animation = new CurvedAnimation(parent: _controller, curve: Curves.linear);
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
body: new Container(
child: new Center(
child: new ScaleTransition( …Run Code Online (Sandbox Code Playgroud) 我正在做一个项目,我需要对一个包含对象的列表进行排序,但它给出了一个错误。
The expression here has a type of 'void', and therefore can't be used.
Run Code Online (Sandbox Code Playgroud)
这是我的代码:-
@override
void initState() {
super.initState();
subscription = collectionReference.snapshots().listen((datasnapshot) {
setState(() {
messageList = datasnapshot.documents
.map(
(v) => Message(
message: v.data['msg'],
sender: v.data['sender'],
imgUrl: v.data['imgUrl'],
id: v.data['id']),
)
.toList().sort((m, m2) => int.parse(m.id).compareTo(int.parse(m2.id)));
});
});
}
Run Code Online (Sandbox Code Playgroud)
它在排序方法中引发错误:-
.toList().sort((m, m2) => int.parse(m.id).compareTo(int.parse(m2.id)));
Run Code Online (Sandbox Code Playgroud)
我应该怎么做才能修复它,或者有没有其他方法可以对对象列表进行排序。
还有一个问题。我的 firestore 集合中的文档没有按时间顺序添加。所以,我必须手动完成。有谁知道为什么他们没有按时间顺序作为默认排序?
提前致谢。