我班上有这个构造函数.现在,就像这样,我明白了
The type parameter icon is annotated with @required
but only named parameters without default value can be annotated with it.
Run Code Online (Sandbox Code Playgroud)
-
const Category(
@required this.name,
@required this.icon,
@required this.color
) : assert(name != null),
assert(icon != null),
assert(color != null);
Run Code Online (Sandbox Code Playgroud)
当像这样调用构造函数时:
Category(name: _categoryName, icon: _categoryIcon, color: _categoryColor),
Run Code Online (Sandbox Code Playgroud)
这是一个错误.
当我用{}包围构造函数参数时,所有这些都消失了.
这是什么意思?
我想开始一个Flask应用程序.我安装了virtualenvwrapper来管理包但我不能让Atom知道当前项目应该使用virtualenv的python二进制文件.
from flask import Flask, render_template
Run Code Online (Sandbox Code Playgroud)
使用Atom的脚本运行器,我得到一个"ImportError:没有名为flask的模块".
我不想让必须更改到终端来运行应用程序的麻烦
我有一个void指向内存地址的指针.然后,我做
intpointer = void指针
floatpointer = void指针
然后,取消引用它们获取值.
{
int x = 25;
void *p = &x;
int *pi = p;
float *pf = p;
double *pd = p;
printf("x: n%d\n", x);
printf("*p: %d\n", *(int *)p);
printf("*pi: %d\n", *pi);
printf("*pf: %f\n", *pf);
printf("*pd: %f\n", *pd);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
解除引用pi(int指针)的输出为25.但解除引用pf(float指针)的输出为0.000.dereferncing pd(double指针)输出一个不断变化的负分数?
为什么这和字节序有关(我的CPU是小端)?
我正在做Udacity扑动课程.有这个构造函数调用.
child: Category(
name: _categoryName,
color: _categoryColor,
iconLocation: _categoryIcon,
),
Run Code Online (Sandbox Code Playgroud)
当我自己这样做时,我自然地编写了如下构造函数:
const Category({
@required this.name,
@required this.icon,
@required this.color
}) : assert(name != null),
assert(icon != null),
assert(color != null);
Run Code Online (Sandbox Code Playgroud)
忽略断言和@requireds.您使用三个参数调用,因此构造函数必须具有三个参数.
但是,在本练习的解决方案文件中,教师就是这样做的.
const Category({
Key key,
@required this.name,
@required this.color,
@required this.iconLocation,
}) : assert(name != null),
assert(color != null),
assert(iconLocation != null),
super(key: key);
Run Code Online (Sandbox Code Playgroud)
什么是这个关键参数以及为什么类别小部件类(StatelessWidget I presume)的父级正在传递它?
我看过Key课,但我什么都不懂.此页面中没有上下文或我可以使用的示例.
我有以下课程:
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/foundation.dart';
class Hisab with ChangeNotifier {
Map<String, dynamic> _items = {};
Hisab({
@required String hisabDate,
@required double total,
@required bool paidStatus,
@required String timestamp,
@required Timestamp serverTimestamp,
}) {
_items['hisabDate'] = hisabDate;
_items['total'] = total;
_items['paidStatus'] = paidStatus;
_items['timestamp'] = timestamp;
_items['serverTimestamp'] = serverTimestamp;
}
Map<String, dynamic> get items => _items;
}
Run Code Online (Sandbox Code Playgroud)
我创建了这个类来保存 firestore 中的项目,以便我可以允许用户按日期过滤和搜索。
当我尝试在 MultiProvider 中初始化此类时,我必须将参数传递给构造函数。
return MultiProvider(
providers: [
ChangeNotifierProvider<CurrentIndex>(create: (_) => CurrentIndex()),
ChangeNotifierProvider<Cart>(
create: (_) => Cart(),
),
ChangeNotifierProvider<Hisab>(
create: (_) => …Run Code Online (Sandbox Code Playgroud) 我正在跟随谷歌的这个谈话.但是我无法实例化firebase对象.
我有一个package.json文件,并开始:
npm install firebase --save
Run Code Online (Sandbox Code Playgroud)
然后做了以下事情:
let Firebase = require('firebase');
let myFire = new Firebase('[link to my app]');
Run Code Online (Sandbox Code Playgroud)
但是,当我johhny-five从终端运行应用程序时,我收到错误:Firebase is not a function.
我该如何实现对象?Firebase是否更改了API?
注意:我将它注入到repl并运行>> typeof Firebase我得到它实际上是一个'对象'.
我正在尝试实现通用堆栈。
这是界面
package stack;
public interface Stack<T>{
void push(T number);
T pop();
T peek();
boolean isEmpty();
boolean isFull();
}
Run Code Online (Sandbox Code Playgroud)
这是课程
package stack;
import java.lang.reflect.Array;
import java.util.EmptyStackException;
public class StackArray <T> implements Stack<T>{
private int maxSize;
private T[] array;
private int top;
public StackArray(int maxSize) {
this.maxSize = maxSize;
// @SuppressWarnings("unchecked")
this.array = (T[]) Array.newInstance(StackArray.class, maxSize);
this.top = -1;
}
private T[] resizeArray() {
/**
* create a new array double the size of the old, copy the old elements then …Run Code Online (Sandbox Code Playgroud) 当我使用旧的 api 来显示小吃栏时,当用户返回到上一页时,小吃栏就会消失。
在新版本中ScaffoldMessenger.of(context).showSnackBar(),小吃栏保持可见。
另外,当我添加用于删除小吃栏的小吃栏操作时,按下该hide操作,返回上一页后不会隐藏小吃栏。
用户离开当前页面后如何删除小吃栏?
void _successSnackbar(BuildContext context, String message) {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
Icon(FontAwesomeIcons.checkCircle, color: Colors.green[400], size: 35),
const SizedBox(width: 15),
Flexible(child: Text(message, style: TextStyle(color: Colors.green[400], fontSize: 14.5))),
],
),
action: SnackBarAction(
label: 'Hide',
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
},
),
duration: Duration(seconds: 2),
),
);
Run Code Online (Sandbox Code Playgroud) 在解释如何使用Provider包的flutter示例中,有两个模型,Catalog和Model。对于 Catalog 模型,不使用 ChangeNotifier,但对于 Cart 模型则使用它。
为什么 ChangeNotifier 用于 Cart 模型而不是 Catalog 模型?
我的想法是,购物车模型取决于外部(目录模型中)的变化。目录模型是硬编码的,因此无需通知任何人更改。
我的想法正确吗?
PS:这是我的第一个应用程序,在状态管理方面我完全是个菜鸟。
flutter ×5
atom-editor ×1
c ×1
dart ×1
endianness ×1
firebase ×1
generics ×1
java ×1
javascript ×1
node.js ×1
npm ×1
pointers ×1
provider ×1
python ×1
stack ×1
virtualenv ×1