I've successfully displayed a hardcoded JSON with a DataTable, like this:
final List<Map<String, String>> listOfPetrol = [
{"logo": "assets/images/shell.jpg", "location": "Johnson Road 1235", "distance": "0.2 KM", "price":"\$12.45", "facilities":"ATM, Restaurant"},
{"logo": "assets/images/sinopec.jpg", "location": "Hennessy Road", "distance": "0.5 KM", "price":"\$10.00", "facilities":"Toilet"},
{"logo": "assets/images/shell.jpg", "location": "Lockhart Rd", "distance": "0.9 KM", "price":"\$11.20", "facilities":"ATM"}
];
DataTable(
columns: [
DataColumn(label: Text('Logo')),
DataColumn(label: Text('Location')),
DataColumn(label: Text('Distance')),
DataColumn(label: Text('Price')),
DataColumn(label: Text('Facilities')),
],
rows:
listOfPetrol
.map(
((element) => DataRow(
cells: <DataCell>[
DataCell(Image.asset(element["logo"])),
DataCell(Text(element["location"])),
DataCell(Text(element["distance"])),
DataCell(Text(element["price"])),
DataCell(Text(element["facilities"])),
],
)),
)
.toList(),
),
Now, I want fetch the JSON from HTTP API, instead. I already figured out this part. Well... kinda:
FetchPetrolList() async {
var data = await http.get("http://157.230.131.4/gda-api-dev/petrol.php");
var jsonData = json.decode(data.body);
List<PetrolItem> petrolList = [];
for (var u in jsonData) {
PetrolItem petrol = PetrolItem(u["logo"], u["location"], u["distance"], u["price"], u["facilities"]);
petrolList.add(petrol);
print(petrol.logo+" "+petrol.location+" "+petrol.distance+" "+petrol.price+" "+petrol.facilities);
}
}
Then how I pass the JSON to the DataTable?
Full code: https://gist.github.com/anta40/5b172d885795c71417f2ed2dccffe50c
You can parse JSON data into a model. There are two ways I use to parse JSON data automatically.
On-line Generation
Install Flutter JsonBeanFactory plug-in generation
Android studio installs the Flutter JsonBeanFactory plug-in in a simple way, which I won't say here.
Right-click the package directory after installation, and select new
Then select dart bean class File from JSON
Then paste the JSON data into the input box, enter the class name, and click make.
So the entity class is generated.
Related
Im using this package https://pub.dev/packages/pluto_menu_bar . I want to know do we have any easy way to add dynamic data and select them on tap,
when I had passed static data and its working fine but when larger data coming from the Database its not working
PlutoMenuItem(
title: 'Province',
children: [
PlutoMenuItem.checkbox(
title: 'Sindh',
initialCheckValue: false,
onChanged: (flag) {
flag == true
? provinceSelectedList.add("Sindh")
: provinceSelectedList.remove("Sindh");
},
),]
I want to create a table like this in Flutter.
When I try to do this using Datatable or Table widgets, it gives me an error. It says because the number of columns of each row in the table must be equal. I solved this problem by using a different table widget. For now, I created two tables and used a table widget, one with fewer columns and the other with the same number of columns.
Column(
children: [
Table(
children: const [
TableRow(children: [
Text("Column Header"),
])
],
),
Table(
children: const [
TableRow(children: [
Text("Col1"),
Text("Col2"),
Text("Col3"),
Text("Col4"),
]),
TableRow(children: [
Text("x1"),
Text("x5"),
Text("x9"),
Text("x13"),
])
],
),
],
)
But is there a better way to do this?
After doing some research on the internet, I found a library called Syncfusion. I solved my problem with stacked headers provided by this library.
It provides us like this table:
Good Day. Am a beginner in flutter and here's what am trying to achieve.
Am creating a form where users can edit payout account details. Account Name is a text field, Account Number is a Text Field, i want Bank Name to be a drop down because i'm using bulk payment system, so the bank name would need to match the slug or else it'll show invalid on my payment merchant.
Here's the code for the form if all fields are just text fields..
labelText:"Bank Name".i18n,
keyboardType:TextInputType.multiline,
textEditingController: vm.instructionsTEC,
).py12(),```
I TRIED REPLACING IT WITH THIS
DropdownButton<String>(
items: <String>['abbey-mortgage-bank',
'above-only-mfb',
'access-bank',
'access-bank-diamond',
'alat-by-wema',
'amju-unique-mfb',
'asosavings',
'bainescredit-mfb',
'bowen-microfinance-bank',
'carbon',
'cemcs-microfinance-bank',
'citibank-nigeria',
'coronation-merchant-bank',
'ecobank-nigeria',
'ekondo-microfinance-bank',
'eyowo',
'fidelity-bank',
'firmus-mfb',
'first-bank-of-nigeria',
'first-city-monument-bank',
'fsdh-merchant-bank-limited',
'globus-bank',
'gomoney',
'guaranty-trust-bank',
'hackman-microfinance-bank',
'hasal-microfinance-bank',
'heritage-bank',
'ibile-mfb',
'infinity-mfb',
'jaiz-bank',
'kadpoly-mfb',
'keystone-bank',
'kredi-money-mfb',
'kuda-bank',
'lbic-plc',
'links-mfb',
'mayfair-mfb',
'mint-mfb',
'paga',
'palmpay',
'parallex-bank',
'parkway-ready-cash',
'paycom',
'petra-microfinance-bank-plc',
'polaris-bank',
'providus-bank',
'quickfund-mfb',
'rand-merchant-bank',
'rubies-mfb',
'sparkle-microfinance-bank',
'stanbic-ibtc-bank',
'standard-chartered-bank',
'sterling-bank',
'suntrust-bank',
'taj-bank',
'tangerine-money',
'tcf-mfb',
'titan-bank',
'union-bank-of-nigeria',
'united-bank-for-africa',
'unity-bank',
'vfd',
'wema-bank',
'zenith-bank'].map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (_) {},
).py12(),
I ran the APK it just shows a blank screen when this page Is loaded.
Use DropDownSearch() widget for that as below.
Add following dependency in your pubspec.yml :
dropdown_search: ^0.6.3
And click on pub get
Import the class-
import 'package:dropdown_search/dropdown_search.dart';
Then use the following code :
DropdownSearch<String>(
//mode of dropdown
mode: Mode.DIALOG,
//to show search box
showSearchBox: true,
showSelectedItem: true,
//list of dropdown items
items: [
"India",
"USA",
"Brazil",
"Canada",
"Australia",
"Singapore"
],
label: "Country",
onChanged: print,
//show selected item
selectedItem: "India",
),
Fore more details you can see here
I am trying to create polyline map using mapbox, which I am able to create properly.
User can come back and can see see polyline maps in his profile.
Doubt - Is there any way I can convert my list of lat long into some format and store in db and later on we fetch it from db and render map?
I checked geojson format also but if we use geoJson with mapbox it generates static maps.
I am using flutter_map to generate maps.
Updated -
var geoJson = {
"type": "polyline",
"coordinates": [
[
76.61219358444214,
27.555764420824236
],
[
76.6120433807373,
27.55395717009122
],
[
76.61094903945923,
27.55285378133631
],
[
76.61021947860718,
27.55138892051556
],
[
76.61000490188599,
27.550285505956428
],
[
76.6101336479187,
27.549372326903264
],
[
76.6107988357544,
27.548287916916344
],
[
76.61150693893433,
27.547831320034653
],
[
76.61109924316406,
27.54568148421033
],
[
76.61097049713135,
27.54391211873852
]
]
}
Currently I am using flutter_map package and using below code to render map.
var points = [LatLng(latitude:27.591585, longitude:76.61139), LatLng(latitude:27.591548, longitude:76.611397), LatLng(latitude:27.591473, longitude:76.611407), LatLng(latitude:27.591437, longitude:76.611413), LatLng(latitude:27.591362, longitude:76.611425), LatLng(latitude:27.591325, longitude:76.61143), LatLng(latitude:27.59125, longitude:76.611442), LatLng(latitude:27.591177, longitude:76.611452), LatLng(latitude:27.59114, longitude:76.611458), LatLng(latitude:27.591065, longitude:76.61147), LatLng(latitude:27.591028, longitude:76.611475), LatLng(latitude:27.591007, longitude:76.611587), LatLng(latitude:27.591013, longitude:76.611693), LatLng(latitude:27.590777, longitude:76.611805), LatLng(latitude:27.590657, longitude:76.611822), LatLng(latitude:27.590535, longitude:76.61184), LatLng(latitude:27.590413, longitude:76.611857), LatLng(latitude:27.590293, longitude:76.611875), LatLng(latitude:27.590172, longitude:76.611892)]
return new Scaffold(
appBar: new AppBar(title: new Text('Leaflet Maps')),
body: new FlutterMap(
options: new MapOptions(
center: new LatLng(27.563896, 76.600460), minZoom: 10.0),
layers: [
new TileLayerOptions(
urlTemplate:
"https://api.mapbox.com/styles/v1/jainaman8/ckd5v8bs00zm01ir3w3bjrrb3/tiles/256/{z}/{x}/{y}#2x?access_token=ACCESS_TOKEN",
additionalOptions: {
'accessToken': '',
'id': 'mapbox.mapbox-streets-v8'
}
),
new PolylineLayerOptions(
polylines: [
new Polyline(
points: points,
strokeWidth: 2.0,
color: Colors.red
)
]
)
I want to store geoJson object into firebase and then pull this data from there and render map using mapbox.
I read on google that firebase does not support arrays so another doubt is that how can I store this data on firebase ?
You can do the desired by making a collection of field of type geopoint and then get those fields in your flutter project.
I want to make a dropdown list, in which one can select the country. The drop down list must be searchable, whenever we type a letter, the drop down list changes.
The drop down list is using a api/json data.
We are not making selection Manually.
you can use searchable_dropdown or dropdown_search packages
For API/JSON question :
check out the second package example in Readme
example
DropdownSearch<UserModel>(
label: "Name",
onFind: (String filter) async {
var response = await Dio().get(
"http://5d85ccfb1e61af001471bf60.mockapi.io/user",
queryParameters: {"filter": filter},
);
var models = UserModel.fromJsonList(response.data);
return models;
},
onChanged: (UserModel data) {
print(data);
},
);