我有一个正在侦听playerList类更改的提供程序:
import 'package:flutter/material.dart';
import 'package:scam_artist/constants/PlayerColors.dart';
import 'package:scam_artist/models/Player.dart';
class PlayerList with ChangeNotifier {
List<Player> _players = [];
List<Player> get players {
return [..._players];
}
void addPlayer(Key key, String name, int index) {
_players.add(
new Player(key: key, color: PlayerColors.colors[index], name: name));
notifyListeners();
}
void editPlayerName(String newName, int index) {
_players[index].name = newName;
notifyListeners();
}
void editPlayerColor(Color newColor, int index) {
_players[index].color = newColor;
notifyListeners();
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我调用函数将值Player更改为对象之一(例如更改名称)时,列表不会使用新数据更新对象。
我需要另一个提供者来Player上课吗?如果是这样,我如何让PlayerList提供者监听提供者的变化Player?
做一些研究,我认为 ProxyProvider 可能是我正在寻找的,但我不确定如何实现它。
Player …
我的教授建议我们用它qsort()来排序一系列结构.但是,我必须发现它不稳定.我知道还有其他关于这个主题的帖子,但似乎都没有提供一个简单的方法来稳定我的排序.有没有办法可以qsort()用于第二个数据字段?
这是我的代码:
#include <stdlib.h>
#include <stdio.h>
struct Map * collect_values(int n, int *arr);
void sort_values(struct Map *ptr, int n);
void print(struct Map *print_struct, int n);
struct Map{
int value, position;
};
int compare(const void *aptr, const void *bptr){
int a = ((struct Map*)aptr)->value, b = ((struct
Map*)bptr)->value;
return (a > b) - (a < b);
}
int main(){
int size, i;
scanf("%d", &size);
int *arr = (int*) malloc(size*sizeof(int));
struct Map *p = collect_values(size,arr);
qsort(p,size,sizeof(struct Map),compare);
print(p,size); …Run Code Online (Sandbox Code Playgroud)