我目前有一个用户的个人资料页面,其中显示了他们的出生日期和其他详细信息。但是我打算通过计算今天的日期和从用户那里获得的出生日期之间的差值来找到他们生日前的日子。
用户的出生日期
这是使用intl包获得的今天的日期。
今天的日期
I/flutter ( 5557): 09-10-2018
Run Code Online (Sandbox Code Playgroud)
我现在面临的问题是,如何计算这两个日期的天数差异?
是否有任何特定的配方或包装可供我检查?
我目前正在构建一个应用程序,以通过api读取数据,并且试图从JSON Placeholder解析JSON api。
我为用户创建了一个模型类(users_future_model.dart):
class Users {
final int userID;
final String name;
final String username;
final String email;
final Address address;
Users({this.userID, this.name, this.username, this.email, this.address});
factory Users.fromJson(Map<String, dynamic> usersjson)=> Users(
userID: usersjson["id"],
name: usersjson["name"],
username: usersjson["username"],
email: usersjson["email"],
address: Address.fromJson(usersjson["address"])
);
}
class Address{
final String street;
final String suite;
final String city;
final String zipcode;
Address({this.street, this.suite, this.city, this.zipcode});
factory Address.fromJson(Map<String, dynamic> addjson){
return Address(
street: addjson["street"],
suite: addjson["suite"],
city: addjson["city"],
zipcode: addjson["zipcode"]
);
}
}
Run Code Online (Sandbox Code Playgroud)
这是将json读取到小部件中的main.dart: …
我在Flutter中有一个Json解析项目,Json如下:
{
"Dependents":[
{
"Name": "Kim",
"Relationship": "Parent",
"Entitlements": [
{
"GP": {
"Entitlement": "10000",
"Utilisation": "500",
"Balance": "9500"
}
},
{
"OPS": {
"Entitlement": "10000",
"Utilisation": "500",
"Balance": "9500"
}
},
{
"IP": {
"Entitlement": "10000",
"Utilisation": "500",
"Balance": "9500"
}
},
{
"Dental": {
"Entitlement": "10000",
"Utilisation": "500",
"Balance": "9500"
}
},
{
"Optical": {
"Entitlement": "10000",
"Utilisation": "500",
"Balance": "9500"
}
},
{
"Maternity": {
"Entitlement": "10000",
"Utilisation": "500",
"Balance": "9500"
}
}
]
},
{
"Name": …
Run Code Online (Sandbox Code Playgroud) 我做了一个应用程序来显示一个州的医院列表.
这是Main.dart
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'dart:async' show Future;
import 'package:flutter/services.dart' show rootBundle;
import 'dart:convert';
import 'package:emas_app/model/accounts_model.dart';
Future<String> _loadAsset() async{
return await rootBundle.loadString('Assets/accounts.json');
}
Future<Accounts> loadAccounts() async{
final response = await _loadAsset();
final jsonResponse = json.decode(response);
Accounts accounts = new Accounts.fromJson(jsonResponse);
return accounts;
}
class ProviderList extends StatefulWidget {
@override
ListState createState() {
return new ListState();
}
}
class ListState extends State<ProviderList> {
@override
Widget build(BuildContext context) {
Widget newbody = new ExpansionTile(
title: new Text("State Name"),
children: …
Run Code Online (Sandbox Code Playgroud) 我目前有一个应用程序可以通过 JSON 提取提供者列表。
这是 JSON 文件。
医院.json
{
"Johor": [
{
"Name": "KLINIK TAJ (MUAR)",
"TPA Customer ID": "1168",
"Organization Type": "Clinic",
"Organization Subtype": "GP",
"Street (Billing)": "35a, jalan abdullah ",
"City (Billing)": "muar",
"Postal Code (Billing)": "84000",
"State (Billing)": "Johor",
"Country (Billing)": "Malaysia",
"Coordinates": {
"Latitude": "2.041875",
"Longitude": "102.568235"
}
},
{
"Name": "KLINIK TAJ (PAGOH)",
"TPA Customer ID": "1169",
"Organization Type": "Clinic",
"Organization Subtype": "GP",
"Street (Billing)": "100 Main Road Pagoh",
"City (Billing)": "Muar",
"Postal Code (Billing)": "84600", …
Run Code Online (Sandbox Code Playgroud) 我目前有一个简单的 API,但是如果不重新启动整个应用程序,我的 flutter 小部件就无法检测到 API 中发生的变化。
该 API 是在https://www.mockable.io/上作为测试 API 制作的。我设法使用StreamBuilder从这个 API 读取。每当我在 API 中更新它们的值时,它仍然不会更改小部件中的值。
默认 JSON
{
"id": "123",
"token": "1token",
"status": "Valid"
}
Run Code Online (Sandbox Code Playgroud)
值更改后
{
"id": "123",
"token": "1token",
"status": "Not Valid"
}
Run Code Online (Sandbox Code Playgroud)
我的 StreamBuilder 代码
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
final String url = "http://demo2722084.mockable.io/user";
class StreamPage extends StatefulWidget {
@override
StreamPageState createState() {
return new StreamPageState();
}
}
class StreamPageState extends State<StreamPage> {
StreamController _userController;
Future fetchUser() …
Run Code Online (Sandbox Code Playgroud) 我有一个 JSON 应用程序调用用户,但在处理空地图时遇到问题。
这是 Json 文件。
会员信息.json
{
"Dependents": [
{
"Name": "Kim",
"Relationship": "Parent",
"Entitlements": {
"GP": {
"Entitlement": "10000",
"Utilisation": "500",
"Balance": "9500"
},
"OPS": {
"Entitlement": "10000",
"Utilisation": "500",
"Balance": "9500"
},
"IP": {
"Entitlement": "50000",
"Utilisation": "17000",
"Balance": "33000"
}
}
},
{
"Name": "Tim",
"Relationship": "Spouse",
"Entitlements": {
"GP": {
"Entitlement": "10000",
"Utilisation": "500",
"Balance": "9500"
},
"OPS": {
"Entitlement": "10000",
"Utilisation": "500",
"Balance": "9500"
},
"IP": {
}
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
dart文件如下:
import …
Run Code Online (Sandbox Code Playgroud) 下面是我的模型类:
\n\ncrm_dependent_list_model.dart(模型类)
\n\nimport \'crm_dep_entitlement_model.dart\';\n\nclass DependantModel{\n\n String name;\n String relationship;\n EntitlementsModel entitlements;\n\n DependantModel({this.name, this.relationship, this.entitlements});\n\n factory DependantModel.fromJson(Map depjson){\n\n return DependantModel(\n name: depjson["Name"].toString(),\n relationship: depjson["Relationship"].toString(),\n entitlements: EntitlementsModel.fromJson(depjson["Entitlements"])\n );\n }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n这是位于DependantModel 类内的EntitlementsModel
\n\ncrm_dep_entitlement_model.dart
\n\nclass EntitlementsModel{\n\n final GP gp;\n final OPS ops;\n final IP ip;\n final Dental dental;\n final Optical optical;\n final EHS ehs;\n\n EntitlementsModel({this.gp, this.ops, this.ip, this.dental, this.optical, this.ehs});\n\n factory EntitlementsModel.fromJson(Map ejson){\n\n return EntitlementsModel(\n\n gp: GP.fromJson(ejson["GP"]),\n ops: OPS.fromJson(ejson["OPS"]),\n ip: IP.fromJson(ejson["IP"]),\n dental: Dental.fromJson(ejson["Dental"]),\n optical: Optical.fromJson(ejson["Optical"]),\n ehs: EHS.fromJson(ejson["EHS"])\n …
Run Code Online (Sandbox Code Playgroud) 我目前有一个应用程序可以显示半径 1.5 公里内的附近医院,它看起来像这样:
我遇到的麻烦是我无法弄清楚如何根据计算出的从最低到最高的距离对卡片进行排序。
我做了一个List<double> doubleList = [];
来存储计算距离的列表并用doubleList.sort();
.
这是代码片段:
return new ListView.builder(
shrinkWrap: true,
itemCount: jsonresponse.length,
itemBuilder: (context, index){
String name = jsonresponse[index]["Name"];
String lat = jsonresponse[index]["Latitude"];
String lng = jsonresponse[index]["Longitude"];
var distance = new GreatCircleDistance.fromDegrees(latitude1: double.parse(widget.lat), longitude1: double.parse(widget.lng), latitude2: double.parse(lat), longitude2: double.parse(lng));
var totaldistance = distance.haversineDistance().toStringAsFixed(2);
double distanceDouble = double.parse(totaldistance);
if(distanceDouble < 1500.00){
doubleList.add(distanceDouble);
doubleList.sort((a, b){
return a.compareTo(b);
});
print(doubleList);
return new Column(
children: <Widget>[
new Card(
child: new ListTile(
title: new Text(name),
subtitle: new …
Run Code Online (Sandbox Code Playgroud) 目前我有一个看起来像这样的地图,可以通过 API 发送电子邮件:
Map body = {"personalizations": [
{
"to": [
{
"email": "$receiverEmail"
}
],
"dynamic_template_data": {
"EmployeeName": "$employeeName",
"EmployeeID": "$employeeID",
"PatientName": "$patientName",
"ProviderName": "$providerName",
"TreatmentDate": "$treatmentDate",
"Diagnosis": "$diagnosis"
}
}
],
"from": {
"email": "$userEmail"
},
"template_id": "$templateID"
};
Run Code Online (Sandbox Code Playgroud)
我计划将此结构与 2 种形式的电子邮件一起使用,为此我需要在dynamic_template_data键下更新/添加值。
因此,我试图找出如何更新/添加该特定键的值。我找到了一个名为Map.update()的函数,但我不确定如何正确使用它。我该如何解决这个问题?
我正在制作一个通过JSON解析获取值的应用程序.我的应用程序有多个选项卡,但每次在选项卡之间滑动时,JSON每次都会发送一个新的读取请求.以下是我的代码:
Home.dart(保存导航标签)
import 'package:flutter/material.dart';
import './First.dart' as first;
import './Second.dart' as second;
import './Third.dart' as third;
import './Fourth.dart' as fourth;
import './Fifth.dart' as fifth;
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => new _HomePageState();
}
class _HomePageState extends State<HomePage> with SingleTickerProviderStateMixin {
final List<NewPage> _tabs = [
new NewPage(title: "Providers Near Me",color: Colors.blue[500]),
new NewPage(title: "Providers Search",color: Colors.blueGrey[500]),
new NewPage(title: "Providers List",color: Colors.teal[500]),
new NewPage(title: "My Info",color: Colors.indigo[500]),
new NewPage(title: "My Dependents Info",color: Colors.red[500]),
];
NewPage _myHandler;
TabController tabController; …
Run Code Online (Sandbox Code Playgroud) 我尝试生成的小部件是一个下拉按钮,我正在使用 flutter Get包进行状态管理。
\n控制器:
\n // Getter and Setter for Downdown List Item\n RxList<DropdownMenuItem<ListItem>> _dropdownMenuItems = [].obs;\n set setDropdownValues(value) => _dropdownMenuItems(value);\n List<DropdownMenuItem<ListItem>> get getDropdownValues => _dropdownMenuItems\n .map((e) => DropdownMenuItem(\n value: e.value,\n child: Text(e.value.name))).toList();\n\n // Getter and Setter for Items Selected from the dropdown\n Rx<ListItem> _selectedItem = ListItem().obs;\n set setSelectedItem(value) => _selectedItem(value);\n get getSelectedItem => _selectedItem.value;\n\n // OnInit\n @override\n void onInit() {\n super.onInit();\n setDropdownValues = buildDropDownMenuItems(); // Sets dropdown list\n setSelectedItem = getDropdownValues[0].value; // Sets selected item as the …
Run Code Online (Sandbox Code Playgroud)