Skip to content

Commit

Permalink
get json from my server
Browse files Browse the repository at this point in the history
  • Loading branch information
sahar-android committed Feb 17, 2022
1 parent 0e75ef5 commit 8d8269d
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 29 deletions.
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ir.simyapp.store_app_flutter">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:label="store_app_flutter"
android:name="${applicationName}"
Expand Down
89 changes: 61 additions & 28 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'ShopButtomNavigator.dart';
import 'package:http/http.dart';
import 'dart:developer';
import 'package:flutter/foundation.dart';


void main() => runApp(store());

Expand All @@ -10,11 +16,19 @@ class store extends StatefulWidget {
}

class _storeState extends State<store> {

@override
void initState() {
// TODO: implement initState
super.initState();
fetchItems();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.blue[50],
appBar: AppBar(
elevation: 30,
title: Text(
Expand Down Expand Up @@ -42,8 +56,9 @@ class _storeState extends State<store> {
child: Icon(Icons.add),
onPressed: () {},
),
body: Padding(
padding: const EdgeInsets.all(15.0),
body:

Padding(padding: const EdgeInsets.all(15.0),
child: GridView.count(
mainAxisSpacing: 15,
crossAxisSpacing: 10,
Expand All @@ -57,42 +72,60 @@ class _storeState extends State<store> {
),
);
}

void fetchItems() async{
//var url='http://www.welearnacademy.ir/flutter/products_list.json';
var url='https://www.simyapp.ir/products.json';
Response response=await get(Uri.parse(url));
print(response.statusCode);
print(utf8.decode(response.bodyBytes));
var test=utf8.decode(response.bodyBytes);
// String jsonsDataString = response.body.toString(); // toString of Response's body is assigned to jsonDataString
// var _data = jsonDecode(jsonsDataString);
//print(_data.toString());
debugPrint('movieTitle: $test');
}
}

Card generateItem() {
return Card(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 90,
height: 90,
child:
Image.network("https://malleys.com/wp-content/uploads/2017/02/bigstock-Chocolate-Covered-Strawberries-165270170.jpg"),
),
Container(
margin: EdgeInsets.only(top: 15),
child: Text("قیمت",
style: TextStyle(
fontFamily: "Vazir",
color: Colors.blue[600],
fontSize: 14.0,

),
),
),
Container(
margin: EdgeInsets.only(top: 15),
child: Text("عنوان",
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0)
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 90,
height: 90,
child:
Image.network('https://flutter.github.io/assets-for-api-docs/assets/widgets/owl.jpg'),
),
Container(
margin: EdgeInsets.only(top: 15),
child: Text("قیمت",
style: TextStyle(
fontFamily: "Vazir",
color: Colors.blue[600],
fontSize: 14.0,
fontWeight: FontWeight.bold,

),
),
),
)
],
Container(
margin: EdgeInsets.only(top: 15),
child: Text("عنوان",
style: TextStyle(
fontFamily: "Vazir",
color: Colors.blue[600],
fontSize: 14.0,
fontWeight: FontWeight.bold,
),
),
)
],
),
),
);
}
8 changes: 8 additions & 0 deletions local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Wed Feb 16 18:47:15 IRST 2022
sdk.dir=C\:\\Users\\Sahar\\AppData\\Local\\Android\\Sdk
37 changes: 37 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
http:
dependency: "direct main"
description:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.13.4"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0"
lints:
dependency: transitive
description:
Expand Down Expand Up @@ -109,6 +123,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
permission_handler:
dependency: "direct main"
description:
name: permission_handler
url: "https://pub.dartlang.org"
source: hosted
version: "8.3.0"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "3.7.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -172,3 +207,5 @@ packages:
version: "2.1.1"
sdks:
dart: ">=2.16.1 <3.0.0"
flutter: ">=2.5.0"
google_maps_flutter: "0.4.0"
5 changes: 4 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ version: 1.0.0+1

environment:
sdk: ">=2.16.1 <3.0.0"
google_maps_flutter: 0.4.0

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
Expand All @@ -29,11 +30,13 @@ environment:
dependencies:
flutter:
sdk: flutter

http: ^0.13.4

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
permission_handler: ^8.0.0+2


dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 8d8269d

Please sign in to comment.