Why flutter contacts don't work on Xiaomi device? - arp

I'm new to Flutter and I'm trying to store contact list as name and number in local database. The code I wrote works on the Samsung A21S device that I use as an emulator, but it does not work on devices like Xiaomi, where did I go wrong?
void getContacts() async {
List<Contact>? _contacts;
List<String> contactList = [];
final bool isConnected = await InternetConnectionChecker().hasConnection;
if (isConnected) {
_contacts = await FlutterContacts.getContacts(
withThumbnail: false, withPhoto: false, withProperties: true);
for (var i = 0; i < _contacts.length; i++) {
//Error this line
var num = _contacts[i].phones.first.normalizedNumber;
var name = _contacts[i].displayName;
var nameNum = "$name,$num";
contactList.insert(i, nameNum);
}
print(contactList);
print(contactList.length);
String json = jsonEncode(contactList);
}
}

Related

How to display NFTs of Torus wallet?

I've successfully integrated the Torus wallet and now I am trying to display the NFTs that a person has in the wallet. I am doing it successfully with MetaMask but I am having troubles making it work with Torus. I am guessing I have a problem with the provider? I get the following errors on the browser:
index.ts:225 Uncaught (in promise) Error: unsupported provider (argument="provider", value="[object Object]", code=INVALID_ARGUMENT, version=providers/5.5.2)
at Logger.makeError (index.ts:225)
at Logger.throwError (index.ts:237)
at Logger.throwArgumentError (index.ts:241)
at new Web3Provider (web3-provider.ts:156)
at loadNFTs (UsersNFTs.js:112)
and
VM9765:2 Uncaught ReferenceError: process is not defined
at Object.4043 (<anonymous>:2:13168)
at r (<anonymous>:2:306599)
at Object.8048 (<anonymous>:2:9496)
at r (<anonymous>:2:306599)
at Object.8641 (<anonymous>:2:1379)
at r (<anonymous>:2:306599)
at <anonymous>:2:315627
at <anonymous>:2:324225
at <anonymous>:2:324229
at HTMLIFrameElement.e.onload (index.js:1)
And this is my code:
*** UsersNFTs.js ***
let [torusSdkInstance,setTorusSdkInstance] = useState()
// Import dynamically torus wallet object
useEffect(()=>{
const initialize = async () => {
const torus = (await import("#toruslabs/torus-embed")).default;
setTorusSdkInstance(new torus({}));
}
initialize();
}, [])
const providerOptions = {
"custom-Torus": { //Torus wallet
display: {
logo: 'https://miime.io/images/wallet-login-torus-logo.png',
name: "Torus",
description: "Connect to Torus Wallet"
},
package: torusSdkInstance,
options: {
// apiKey: "EXAMPLE_PROVIDER_API_KEY"
},
connector: async (_, options) => {
await torusSdkInstance.init({
enableLogging: false,
});
await torusSdkInstance.login();
const web3 = new Web3(torusSdkInstance.provider);
return web3;
}
}
}
const web3Modal = new Web3Modal({
network: "mainnet",
cacheProvider: true,
providerOptions
});
const connection = await web3Modal.connect()
const provider = new ethers.providers.Web3Provider(connection)
const signer = provider.getSigner()
const marketContract = new ethers.Contract(nftmarketaddress, Market.abi, signer)
const tokenContract = new ethers.Contract(nftaddress, NFT.abi, provider)
const data = await marketContract.fetchMyNFTs()
*** fetchMyNFTs function in the smart contract ***
function fetchMyNFTs() public view returns (MarketItem[] memory) {
uint totalItemCount = _itemIds.current();
uint itemCount = 0;
uint currentIndex = 0;
for (uint i = 0; i < totalItemCount; i++) {
if (idToMarketItem[i + 1].owner == msg.sender) {
itemCount += 1;
}
}
MarketItem[] memory items = new MarketItem[](itemCount);
for (uint i = 0; i < totalItemCount; i++) {
if (idToMarketItem[i + 1].owner == msg.sender) {
uint currentId = idToMarketItem[i + 1].itemId;
MarketItem storage currentItem = idToMarketItem[currentId];
items[currentIndex] = currentItem;
currentIndex += 1;
}
}
return items;
}
I found the way to display the minted NFTs (not the purchased ones) of a wallet, so I want to share my solution!
I have a fetchNFTs function in my smart contract that gets the tokens made available in the market place but not sold yet (address(0)):
function fetchMarketItems() public view returns (MarketItem[] memory) {
uint itemCount = _itemIds.current();
uint unsoldItemCount = _itemIds.current() - _itemsSold.current();
uint currentIndex = 0;
MarketItem[] memory items = new MarketItem[](unsoldItemCount);
for (uint i = 0; i < itemCount; i++) {
if (idToMarketItem[i + 1].owner == address(0)) {
uint currentId = idToMarketItem[i + 1].itemId;
MarketItem storage currentItem = idToMarketItem[currentId];
items[currentIndex] = currentItem;
currentIndex += 1;
}
}
return items;
}
And in the frontend after I call this function, I just had to map through the items and select the ones which the seller address equals the address of the connected wallet, so I get the NFTs that the address has minted but not sold yet.

(I'm not uploading any file) The request message is too big. the server does not allow messages larger than 2097152

I have a simple list with 108 items, this code was working until today, but some how stop working with the message in the Title.
I'm only passing a simple CAML but I canĀ“t ride of this error.
Anyone have a Suggestion? this is annoying.
private static int GetLookupCity(string city)
{
var oList = Ctx.Web.Lists.GetByTitle("City");
var camlQuery = new CamlQuery
{
ViewXml = "<View><Query><Where><Eq><FieldRef Name=\"Title\"/><Value Type=\"Text\">" + city + "</Value></Eq></Where></Query></View>"
};
var listItems = oList.GetItems(camlQuery);
Ctx.Load(listItems,
items => items.Include(
item => item["ID"],
item => item["Title"]));
Ctx.ExecuteQuery();
foreach (var oListItem in listItems)
{
FieldLookupValue lv = new FieldLookupValue
{
LookupId = int.Parse(oListItem["ID"].ToString())
};
return lv.LookupId;
}
Ctx.Dispose();
return 0;
}
I I'm using this in an Excel Addin, so It's not thread safe. The only way I can put this work was to use the Garbage Collector in all methods.
private static int GetLookupCity(string city)
{
var oList = Ctx.Web.Lists.GetByTitle("City");
var camlQuery = new CamlQuery
{
ViewXml = "<View><Query><Where><Eq><FieldRef Name=\"Title\"/><Value Type=\"Text\">" + city + "</Value></Eq></Where></Query></View>"
};
var listItems = oList.GetItems(camlQuery);
Ctx.Load(listItems,
items => items.Include(
item => item["ID"],
item => item["Title"]));
Ctx.ExecuteQuery();
GC.Collect();
var queryable = listItems.ToList().FirstOrDefault();
FieldLookupValue lv = new FieldLookupValue
{
LookupId = int.Parse(queryable[0]["ID"].ToString())
};
return lv.LookupId;
Ctx.Dispose();
GC.Collect();
return 0;
}

App script/maker and Big Query

I having an google app (app maker) where I script the following code:
function runQuery() {
var projectId = 'projekte-123425512';
var request = {
query: 'SELECT title FROM [bigquery-public-data:samples.wikipedia] where title contains "olimpic" LIMIT 100'
};
var queryResults = BigQuery.Jobs.query(request, projectId);
var jobId = queryResults.jobReference.jobId;
var names = queryResults.schema.fields.map(function(field){ return field.name; });
return queryResults.rows.map(function(row) {
var obj = {};
for( var i = 0, len = names.length; i < len; ++i ) {
obj[names[i]] = row.f[i].v;
}
return obj;
});
}
So I basically try to get some data out of Big Query and store it in an array. Later I want it as a calculated model and a data source in my app:
I already tried it and get result in my logger:
It works! But only in app script debugger, then I want to test the whole app I get the following error:
The function queryRecords must return an array of records, but the array contained an element that was not a record. Error: The function queryRecords must return an array of records, but the array contained an element that was not a record.
EDIT
I updated my code
function runQuery() {
var projectId = 'nifty-stage-155512';
var request = {
query: 'SELECT title FROM [bigquery-public-data:samples.wikipedia] where title contains "olimpic" LIMIT 100'
};
var queryResults = BigQuery.Jobs.query(request, projectId);
var jobId = queryResults.jobReference.jobId;
var names = queryResults.schema.fields.map(function(field){ return field.name; });
//var records = [];
return queryResults.rows.map(function(row) {
var record = app.models.Test.newRecord();
for (var i = 0, len = names.length; i < len; ++i) {
// Calculated model should contain correspondent fields
// all non-defined fields will be ignored
record[names[i]] = (row.f[i].v);
}
return record;
});
}
It now works without error but I still get no data into my grid:
Is there something I'am missing in the configuration of the grid or the datasource??
App Maker doesn't allow to return arbitrary objects through its datasources. All results should be strongly typed:
...
return queryResults.rows.map(function(row) {
var record = app.models.CalcModelName.newRecord();
for (var i = 0, len = names.length; i < len; ++i) {
// Calculated model should contain correspondent fields
// all non-defined fields will be ignored
record[names[i]] = row.f[i].v;
}
return record;
});
Here are some samples for reference
https://developers.google.com/appmaker/samples/calculated-model/
https://developers.google.com/appmaker/samples/jdbc/

Adding Markers to Google map from json Array

This is my poor code
function loaddata() {
var url = "http://localhost/Geocording/api.php";
$.getJSON(url, function (data) {
var json = data
for (var i = 0, length = json.length; i < length; i++) {
var val = json[i],
var latLng = new google.maps.LatLng(val.lat, val.lng);
console.log(latLng)
}
});
}
Im trying to get details from my own api using json array.
but its not working.
{"location":[{"name":"Home 1","lat":"6.824367","lng":"80.034523","type":"1"},{"name":"Grid Tower 1","lat":"6.82371292","lng":"80.03451942","type":"1"},{"name":"Power Station A","lat":"6.82291793","lng":"80.03417451","type":"1"}],"success":1}
This is json response from my api.php
Try to make things clear first then apply it. First read JSON clearly then go on to apply it in your code. This is the working code.
function loaddata() {
var url = "http://localhost/Geocording/api.php";
$.getJSON(url, function (data) {
var json = data['location'];
for (var i = 0, length = json.length; i < length; i++) {
var val = json[i];
var latLng = new google.maps.LatLng(val['lat'], val['lng']);
console.log(latLng)
}
});
}
Hope this may help you!

get download url from multiple file upload firebase storage

I am new in firebase and angularjs and i am having difficulties in getting download url from firebase storage and store them in firebase realtime database.
I was able to upload multiple files to firebase storage. the problem is when i store the download url into firebase realtime database, all database url value are same.It should different based each files downloadURL.
Here my script:
$scope.submitPhotos = function(file){
console.log(file);
var updateAlbum = [];
for (var i = 0; i < file.length; i++) {
var storageRef=firebase.storage().ref(albumtitle).child(file[i].name);
var task=storageRef.put(file[i]);
task.on('state_changed', function progress(snapshot){
var percentage=( snapshot.bytesTransferred / snapshot.totalBytes )*100;
if (percentage==100){
storageRef.getDownloadURL().then(function(url) {
var galleryRef = firebase.database().ref('gallery/'+albumkey);
var postkey = firebase.database().ref('gallery/'+albumkey).push().key;
updateAlbum={img:url};
firebase.database().ref('gallery/'+ albumkey+'/'+postkey).update(updateAlbum);
});
};
})
};
};
As you can see i was able store the url into database but all of the urls are same. What i need is every key store each different links from storage.
Any helps appreciated. Thanks
function uploadImg(file,i) {
return new Promise((resolve,reject)=>{
var storageRef=firebase.storage().ref("store-images/"+file[i].file.name);
task = storageRef.put(file[i].file);
task.on('state_changed', function progress(snapshot){
var percentage=( snapshot.bytesTransferred / snapshot.totalBytes )*100;
console.log(percentage);
// use the percentage as you wish, to show progress of an upload for example
}, // use the function below for error handling
function (error) {
console.log(error);
},
function complete () //This function executes after a successful upload
{
task.snapshot.ref.getDownloadURL().then(function(downloadURL) {
resolve(downloadURL)
});
});
})
}
async function putImage(file) {
for (var i = 0; i < file.length; i++) {
var dd = await uploadImg(file,i);
firebase.database().ref().child('gallery').push(dd);
}
}
Try using the code below:
$scope.submitPhotos = function(file){
console.log(file);
var updateAlbum = [];
for (var i = 0; i < file.length; i++) {
var storageRef=firebase.storage().ref(albumtitle).child(file[i].name);
var task=storageRef.put(file[i]);
task.on('state_changed', function progress(snapshot)
{
var percentage=( snapshot.bytesTransferred / snapshot.totalBytes )*100;
// use the percentage as you wish, to show progress of an upload for example
}, // use the function below for error handling
function (error) {
switch (error.code) {
case 'storage/unauthorized':
// User doesn't have permission to access the object
break;
case 'storage/canceled':
// User canceled the upload
break;
case 'storage/unknown':
// Unknown error occurred, inspect error.serverResponse
break;
}
}, function complete () //This function executes after a successful upload
{
let dwnURL = task.snapshot.downloadURL;
let galleryRef = firebase.database().ref('gallery/'+albumkey);
let postkey = firebase.database().ref('gallery/'+albumkey).push().key;
updateAlbum={img:dwnURL};
firebase.database().ref('gallery/'+ albumkey+'/'+postkey).update(updateAlbum);
});
};
};
All the best!

Resources