; paras[X - 1].parentNode.insertBefore(ad1, paras[X]); } if (paras.length > X + 4) { var ad1 = document.createElement('div'); ad1.className = 'ad-auto-insert ad-first'; ad1.innerHTML = ` ; paras[X + 3].parentNode.insertBefore(ad2, paras[X + 4]); } if (isMobile && paras.length > X + 8) { var ad1 = document.createElement('div'); ad1.className = 'ad-auto-insert ad-first'; ad1.innerHTML = ` ; paras[X + 7].parentNode.insertBefore(ad3, paras[X + 8]); } });

Advertisement

top 10 ways to boost your immune system

 Helpful ways to strengthen your immune system and fight off disease

How can you improve your immune system? On the whole, your immune system does a remarkable job of defending you against disease-causing microorganisms. But sometimes it fails: A germ invades

create pdf file in flutter


dependencies:
pdf: ^1.9.0

CreatePdf.dart 

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:image/image.dart';
import 'package:movements/Utils.dart';
import 'package:path_provider/path_provider.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;


class CreatePdf extends StatefulWidget {
@override _CreatePdfState createState() => _CreatePdfState();
}

class _CreatePdfState extends State<CreatePdf> {
@override void initState() {
// TODO: implement initState super.initState();
}

@override Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Create PDF"),
elevation: .1,
),
body: Center(
child: Container(
child: FlatButton(
onPressed: () {
createPdf();
},
child: Text("Create PDF")),
),
),
);
}


Future createPdf() async {
final pdf = pw.Document();


pdf.addPage(pw.Page(
pageFormat: PdfPageFormat.a4,
build: (pw.Context context) {
return pw.Center(
child: pw.Text("Hello World"),
); // Center }));

var number = Utils.getRandomNumber(4);
final output =
await getExternalStorageDirectory(); // use the [path_provider (https://pub.dartlang.org/packages/path_provider) library: final file = File("${output.path}/example" + number.toString() + ".pdf");
await file.writeAsBytes(pdf.save());
}
}

Flutter Keystore generate command



Go to  Java installation folder bin,

Now use the below keytool command to generate keystore file. Go to the java bin path in command line tool and use below command


keytool -genkey -v -keystore "D:/AppkeyStore.jks" -keyalg RSA -keysize 2048 -validity 10000 -alias "AppAliasName"


To check expiration of the jsk file.

keytool -list -v -keystore AppkeyStore.jks




keytool -importkeystore -srckeystore /Users/pratapkumar/Desktop/shary/sharyAppkeyStore.jks -destkeystore /Users/pratapkumar/Desktop/shary/sharyAppkeyStore.jks -deststoretype pkcs12

Flutter GPS Location

In this tutorial , we try to fetch phone GPS Location.





I used this library in pubspec.yaml file under dependencies

dependencies:
location: ^2.3.5


Android #



In order to use this plugin in Android, you have to add this permission in AndroidManifest.xml :

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Permission check for Android 6+ was added.

iOS #

And to use it in iOS, you have to add this permission in Info.plist :
NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription
Warning: there is a currently a bug in iOS simulator in which you have to manually select a Location several in order for the Simulator to actually send data. Please keep that in mind when testing in iOS simulator.

main.dart


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import 'package:flutter/material.dart';
import 'package:flutter_app_sample/GetLocationPage.dart';



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

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter GPS',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: GetLocationPage(),
);
}
}




GetLocationPage.dart



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import 'package:flutter/material.dart';
import 'package:location/location.dart';

class GetLocationPage extends StatefulWidget {
@override
_GetLocationPageState createState() => _GetLocationPageState();
}

class _GetLocationPageState extends State<GetLocationPage> {
LocationData _currentLocation;
Location _locationService = new Location();

@override
void initState() {
// TODO: implement initState
super.initState();

_getLocation().then((value) {
setState(() {
_currentLocation = value;
});
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_currentLocation == null
? CircularProgressIndicator()
: Text("Location:" +
_currentLocation.latitude.toString() +
" " +
_currentLocation.longitude.toString()),
Padding(
padding: const EdgeInsets.all(8.0),
child: RaisedButton(
onPressed: () {
_getLocation().then((value) {
setState(() {
_currentLocation = value;
});
});
},
color: Colors.blue,
child: Text(
"Get Location",
style: TextStyle(color: Colors.white),
),
),
),
],
),
),
);
}

Future<LocationData> _getLocation() async {
LocationData currentLocation;
try {
currentLocation = await _locationService.getLocation();
} catch (e) {
currentLocation = null;
}
return currentLocation;
}
}

Flutter Infinite ListView using Webservice


In this tutorial, we will see how to implement Infinite ListView in Flutter using webservice.



Here is the reference link i used most of the code but i used webservice in this tutorial.

Thanks to author of the tutorial
https://marcinszalek.pl/flutter/infinite-dynamic-listview/


Now Let see using this webservice
https://api.randomuser.me/?page=1&results=20&seed=abc

Here page number increments after scroll reaches the end.

Demo:
=======


main.dart
==========

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import 'package:akeepo/randomuser_infinitelist.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,

),
home: InfiniteUsersList(),



);
}
}


randomuser_infinitelist.dart
=============================

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import 'dart:async';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

class InfiniteUsersList extends StatefulWidget {
static String tag = 'users-page';

@override
State<StatefulWidget> createState() {
return new _InfiniteUsersListState();
}
}

class _InfiniteUsersListState extends State<InfiniteUsersList> {
List<User> users = new List<User>();
ScrollController _scrollController = new ScrollController();
bool isPerformingRequest = false;
int pageNumber = 0;

@override
void initState() {
super.initState();

// Loading initial data or first request to get the data
_getMoreData();

// Loading data after scroll reaches end of the list
_scrollController.addListener(() {
if (_scrollController.position.pixels ==
_scrollController.position.maxScrollExtent) {
_getMoreData();
}
});
}

// to show progressbar while loading data in background
Widget _buildProgressIndicator() {
return new Padding(
padding: const EdgeInsets.all(8.0),
child: new Center(
child: new Opacity(
opacity: isPerformingRequest ? 1.0 : 0.0,
child: new CircularProgressIndicator(),
),
),
);
}

@override
void dispose() {
_scrollController.dispose();
super.dispose();
}

// Webservice request to load 20 users data using paging
Future<List<User>> _getUsers() async {
List<User> users = new List<User>();
setState(() {
pageNumber++;
});

String url =
"https://api.randomuser.me/?page=$pageNumber&results=20&seed=abc";
print(url);

var response = await http.get(url);
var jsonData = json.decode(response.body);

print(jsonData);

var usersData = jsonData["results"];
for (var user in usersData) {
User newUser = User(user["name"]["first"] + user["name"]["last"],
user["email"], user["picture"]["large"], user["phone"]);
users.add(newUser);
}

return users;
}

_getMoreData() async {
if (!isPerformingRequest) {
setState(() {
isPerformingRequest = true;
});
List<User> newEntries = await _getUsers(); //returns empty list
if (newEntries.isEmpty) {
double edge = 50.0;
double offsetFromBottom = _scrollController.position.maxScrollExtent -
_scrollController.position.pixels;
if (offsetFromBottom < edge) {
_scrollController.animateTo(
_scrollController.offset - (edge - offsetFromBottom),
duration: new Duration(milliseconds: 500),
curve: Curves.easeOut);
}
}
setState(() {
users.addAll(newEntries);
isPerformingRequest = false;
});
}
}

Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Users',
style:
TextStyle(color: Colors.white, fontWeight: FontWeight.bold))),
body: Container(
child: ListView.builder(
shrinkWrap: true,
controller: _scrollController,
itemCount: users.length + 1,
itemBuilder: (BuildContext context, int index) {
if (index == users.length) {
return _buildProgressIndicator();
} else {
return ListTile(
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) =>
UserDetailPage(users[index])));
},
title: Text(users[index].fullName),
subtitle: Text(users[index].mobileNumber),
leading: CircleAvatar(
backgroundImage: NetworkImage(users[index].imageUrl)),
);
}
})),
);
}
}

class User {
final String fullName;

final String email;

final String imageUrl;

final String mobileNumber;

User(this.fullName, this.email, this.imageUrl, this.mobileNumber);
}

// User Detail Page

class UserDetailPage extends StatelessWidget {
final User user;

UserDetailPage(this.user);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("User Details"),
),
body: Center(
child: Text(
user.fullName,
style: TextStyle(fontSize: 35.0),
),
),
);
}
}



Git Commands

Download git
https://git-scm.com/

if you want to add your project to bitbucket or github. you can use the following commands

Step 1:

Right Click-> Git Bash Here or go to the Project folder if you are not using git GUI tools

Step 2:
Type git init (For initializing git).

Step 3:
Type git add -A (Get all files in the staging area).

Step 4:
Type git commit -m "First Commit"(Commit Changes)

Step 5:
Type git remote add origin https://..bitbucket.org/../ABC.git (Your repo URL)

Step 6:
Type git push -f origin master(your branch name)

Flutter Navigation Drawer Example





















main.dart
=========


import 'package:flutter/material.dart';
import 'package:akeepo/navdrawer.dart';
void main() => runApp(MyApp());

class MyApp extends StatelessWidget {


@override Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,

),
home: NavDrawer(),

);
}
}



navdrawer.dart
================


import 'package:flutter/material.dart';

class NavDrawer extends StatefulWidget {
@override _NavDrawerState createState() => _NavDrawerState();
}

class _NavDrawerState extends State<NavDrawer> {
@override Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Nav Drawer")),
drawer: new Drawer(
child: new ListView(
children: <Widget>[
new UserAccountsDrawerHeader(
accountName: new Text("Pratap Kumar"),
accountEmail: new Text("kprathap23@gmail.com"),
decoration: new BoxDecoration(
image: new DecorationImage(
image: new ExactAssetImage('assets/images/lake.jpeg'),
fit: BoxFit.cover,
),
),
currentAccountPicture: CircleAvatar(
backgroundImage: NetworkImage(
"https://randomuser.me/api/portraits/men/46.jpg")),
),
new ListTile(
leading: Icon(Icons.library_music),
title: new Text("Music"),
onTap: () {
Navigator.pop(context);
}),
new ListTile(
leading: Icon(Icons.movie),
title: new Text("Movies"),
onTap: () {
Navigator.pop(context);
}),
new ListTile(
leading: Icon(Icons.shopping_cart),
title: new Text("Shopping"),
onTap: () {
Navigator.pop(context);
}),
new ListTile(
leading: Icon(Icons.apps),
title: new Text("Apps"),
onTap: () {
Navigator.pop(context);
}),
new ListTile(
leading: Icon(Icons.dashboard),
title: new Text("Docs"),
onTap: () {
Navigator.pop(context);
}),
new ListTile(
leading: Icon(Icons.settings),
title: new Text("Settings"),
onTap: () {
Navigator.pop(context);
}),
new Divider(),
new ListTile(
leading: Icon(Icons.info),
title: new Text("About"),
onTap: () {
Navigator.pop(context);
}),
new ListTile(
leading: Icon(Icons.power_settings_new),
title: new Text("Logout"),
onTap: () {
Navigator.pop(context);
}),
],
),
),
);
}
}

UPTET news