Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
permission_handler
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
songyanzhi
permission_handler
Commits
a6a2049a
Commit
a6a2049a
authored
May 10, 2021
by
Jan-Derk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated example app
parent
39caf3c3
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
120 additions
and
383 deletions
+120
-383
permission_handler/CHANGELOG.md
+4
-0
permission_handler/example/lib/main.dart
+109
-123
permission_handler/example/lib/plugin_example/permission_list.dart
+0
-36
permission_handler/example/lib/plugin_example/permission_widget.dart
+0
-87
permission_handler/example/lib/template/globals.dart
+0
-38
permission_handler/example/lib/template/info_page.dart
+0
-98
permission_handler/example/pubspec.yaml
+6
-0
permission_handler/pubspec.yaml
+1
-1
No files found.
permission_handler/CHANGELOG.md
View file @
a6a2049a
## 7.1.1
*
Improved the example app by using the Baseflow Plugin Template and move all the functionality to the
`main.dart`
file.
## 7.1.0
## 7.1.0
*
Added support for the "SYSTEM_ALERT_WINDOW" permission on Android.
*
Added support for the "SYSTEM_ALERT_WINDOW" permission on Android.
...
...
permission_handler/example/lib/main.dart
View file @
a6a2049a
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'
package:flutter/widgets.dart
'
;
import
'
dart:io
'
;
import
'package:baseflow_plugin_template/baseflow_plugin_template.dart'
;
import
'
template/globals
.dart'
;
import
'
package:permission_handler/permission_handler
.dart'
;
void
main
(
)
{
void
main
(
)
{
runApp
(
BaseflowPluginExample
());
runApp
(
BaseflowPluginExample
(
pluginName:
'Permission Handler'
,
githubURL:
'https://github.com/Baseflow/flutter-permission-handler'
,
pubDevURL:
'https://pub.dev/packages/permission_handler'
,
pages:
[
PermissionHandlerWidget
.
createPage
()]));
}
}
///Defines the main theme color
final
MaterialColor
themeMaterialColor
=
BaseflowPluginExample
.
createMaterialColor
(
const
Color
.
fromRGBO
(
48
,
49
,
60
,
1
));
/// A Flutter application demonstrating the functionality of this plugin
/// A Flutter application demonstrating the functionality of this plugin
class
BaseflowPluginExample
extends
StatelessWidget
{
class
PermissionHandlerWidget
extends
StatefulWidget
{
/// [MaterialColor] to be used in the app [ThemeData]
static
ExamplePage
createPage
()
{
final
MaterialColor
themeMaterialColor
=
return
ExamplePage
(
createMaterialColor
(
const
Color
.
fromRGBO
(
48
,
49
,
60
,
1
));
Icons
.
location_on
,
(
context
)
=>
PermissionHandlerWidget
());
}
@override
_PermissionHandlerWidgetState
createState
()
=>
_PermissionHandlerWidgetState
();
}
class
_PermissionHandlerWidgetState
extends
State
<
PermissionHandlerWidget
>
{
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
return
Center
(
title:
'Baseflow
$pluginName
'
,
child:
ListView
(
theme:
ThemeData
(
children:
Permission
.
values
accentColor:
Colors
.
white60
,
.
where
((
permission
)
{
backgroundColor:
const
Color
.
fromRGBO
(
48
,
49
,
60
,
0.8
),
if
(
Platform
.
isIOS
)
{
buttonTheme:
ButtonThemeData
(
return
permission
!=
Permission
.
unknown
&&
buttonColor:
themeMaterialColor
.
shade500
,
permission
!=
Permission
.
sms
&&
disabledColor:
themeMaterialColor
.
withRed
(
200
),
permission
!=
Permission
.
storage
&&
splashColor:
themeMaterialColor
.
shade50
,
permission
!=
Permission
.
ignoreBatteryOptimizations
&&
textTheme:
ButtonTextTheme
.
primary
,
permission
!=
Permission
.
accessMediaLocation
&&
),
permission
!=
Permission
.
activityRecognition
&&
bottomAppBarColor:
const
Color
.
fromRGBO
(
57
,
58
,
71
,
1
),
permission
!=
Permission
.
manageExternalStorage
&&
hintColor:
themeMaterialColor
.
shade500
,
permission
!=
Permission
.
systemAlertWindow
;
primarySwatch:
createMaterialColor
(
const
Color
.
fromRGBO
(
48
,
49
,
60
,
1
)),
}
else
{
textTheme:
TextTheme
(
return
permission
!=
Permission
.
unknown
&&
bodyText1:
TextStyle
(
permission
!=
Permission
.
mediaLibrary
&&
color:
Colors
.
white
,
permission
!=
Permission
.
photos
&&
fontSize:
16
,
permission
!=
Permission
.
reminders
;
height:
1.3
,
}
),
})
bodyText2:
TextStyle
(
.
map
((
permission
)
=>
PermissionWidget
(
permission
))
color:
Colors
.
white
,
.
toList
()),
fontSize:
18
,
height:
1.2
,
),
button:
TextStyle
(
color:
Colors
.
white
),
headline1:
TextStyle
(
color:
Colors
.
white
,
fontSize:
18
,
),
),
visualDensity:
VisualDensity
.
adaptivePlatformDensity
,
inputDecorationTheme:
InputDecorationTheme
(
fillColor:
const
Color
.
fromRGBO
(
37
,
37
,
37
,
1
),
filled:
true
,
),
),
home:
AppHome
(
title:
'Baseflow
$pluginName
example app'
),
);
);
}
}
}
/// Creates a [MaterialColor] based on the supplied [Color]
class
PermissionWidget
extends
StatefulWidget
{
static
MaterialColor
createMaterialColor
(
Color
color
)
{
/// Constructs a [PermissionWidget] for the supplied [Permission].
List
strengths
=
<
double
>[.
05
];
const
PermissionWidget
(
this
.
_permission
);
Map
swatch
=
<
int
,
Color
>{};
final
r
=
color
.
red
,
g
=
color
.
green
,
b
=
color
.
blue
;
for
(
var
i
=
1
;
i
<
10
;
i
++)
{
final
Permission
_permission
;
strengths
.
add
(
0.1
*
i
);
}
@override
for
(
var
strength
in
strengths
)
{
_PermissionState
createState
()
=>
_PermissionState
(
_permission
);
final
ds
=
0.5
-
strength
;
swatch
[(
strength
*
1000
).
round
()]
=
Color
.
fromRGBO
(
r
+
((
ds
<
0
?
r
:
(
255
-
r
))
*
ds
).
round
(),
g
+
((
ds
<
0
?
g
:
(
255
-
g
))
*
ds
).
round
(),
b
+
((
ds
<
0
?
b
:
(
255
-
b
))
*
ds
).
round
(),
1
,
);
}
return
MaterialColor
(
color
.
value
,
swatch
as
Map
<
int
,
Color
>);
}
}
}
/// A Flutter example demonstrating how the [pluginName] plugin could be used
class
_PermissionState
extends
State
<
PermissionWidget
>
{
class
AppHome
extends
StatefulWidget
{
_PermissionState
(
this
.
_permission
);
/// Constructs the [AppHome] class
AppHome
({
Key
?
key
,
this
.
title
})
:
super
(
key:
key
);
/// The [title] of the application, which is shown in the application's
final
Permission
_permission
;
/// title bar.
PermissionStatus
_permissionStatus
=
PermissionStatus
.
denied
;
final
String
?
title
;
@override
@override
_AppHomeState
createState
()
=>
_AppHomeState
();
void
initState
()
{
}
super
.
initState
();
_listenForPermissionStatus
();
}
void
_listenForPermissionStatus
()
async
{
final
status
=
await
_permission
.
status
;
setState
(()
=>
_permissionStatus
=
status
);
}
class
_AppHomeState
extends
State
<
AppHome
>
{
Color
getPermissionColor
()
{
static
final
PageController
_pageController
=
PageController
(
initialPage:
0
);
switch
(
_permissionStatus
)
{
int
_currentPage
=
0
;
case
PermissionStatus
.
denied
:
return
Colors
.
red
;
case
PermissionStatus
.
granted
:
return
Colors
.
green
;
case
PermissionStatus
.
limited
:
return
Colors
.
orange
;
default
:
return
Colors
.
grey
;
}
}
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
return
ListTile
(
appBar:
AppBar
(
title:
Text
(
backgroundColor:
Theme
.
of
(
context
).
bottomAppBarColor
,
_permission
.
toString
(),
title:
Center
(
style:
Theme
.
of
(
context
).
textTheme
.
bodyText1
,
child:
Image
.
asset
(
'res/images/baseflow_logo_def_light-02.png'
,
width:
140
,
),
),
),
),
backgroundColor:
Theme
.
of
(
context
).
backgroundColor
,
subtitle:
Text
(
body:
PageView
(
_permissionStatus
.
toString
(),
controller:
_pageController
,
style:
TextStyle
(
color:
getPermissionColor
()),
children:
pages
,
onPageChanged:
(
page
)
{
setState
(()
{
_currentPage
=
page
;
});
},
),
),
bottomNavigationBar:
_bottomAppBar
(),
trailing:
IconButton
(
icon:
const
Icon
(
Icons
.
info
,
color:
Colors
.
white
,
),
onPressed:
()
{
checkServiceStatus
(
context
,
_permission
);
}),
onTap:
()
{
requestPermission
(
_permission
);
},
);
);
}
}
BottomAppBar
_bottomAppBar
()
{
void
checkServiceStatus
(
BuildContext
context
,
Permission
permission
)
async
{
return
BottomAppBar
(
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
SnackBar
(
elevation:
5
,
content:
Text
((
await
permission
.
status
).
toString
()),
color:
Theme
.
of
(
context
).
bottomAppBarColor
,
));
child:
Row
(
mainAxisSize:
MainAxisSize
.
max
,
mainAxisAlignment:
MainAxisAlignment
.
spaceBetween
,
children:
List
.
unmodifiable
(()
sync
*
{
for
(
var
i
=
0
;
i
<
pages
.
length
;
i
++)
{
yield
Expanded
(
child:
IconButton
(
iconSize:
30
,
icon:
Icon
(
icons
.
elementAt
(
i
)),
color:
_bottomAppBarIconColor
(
i
),
onPressed:
()
=>
_animateToPage
(
i
),
),
);
}
}()),
),
);
}
}
void
_animateToPage
(
int
page
)
{
Future
<
void
>
requestPermission
(
Permission
permission
)
async
{
_pageController
.
animateToPage
(
page
,
final
status
=
await
permission
.
request
();
duration:
Duration
(
milliseconds:
200
),
curve:
Curves
.
linear
);
}
Color
_bottomAppBarIconColor
(
int
page
)
{
setState
(()
{
return
_currentPage
==
page
?
Colors
.
white
:
Theme
.
of
(
context
).
accentColor
;
print
(
status
);
_permissionStatus
=
status
;
print
(
_permissionStatus
);
});
}
}
}
}
permission_handler/example/lib/plugin_example/permission_list.dart
deleted
100644 → 0
View file @
39caf3c3
import
'dart:io'
;
import
'package:flutter/material.dart'
;
import
'package:permission_handler/permission_handler.dart'
;
import
'permission_widget.dart'
;
/// Constructs a [ListView] containing [PermissionWidget] for each available
/// permission.
class
PermissionList
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
Center
(
child:
ListView
(
children:
Permission
.
values
.
where
((
permission
)
{
if
(
Platform
.
isIOS
)
{
return
permission
!=
Permission
.
unknown
&&
permission
!=
Permission
.
sms
&&
permission
!=
Permission
.
storage
&&
permission
!=
Permission
.
ignoreBatteryOptimizations
&&
permission
!=
Permission
.
accessMediaLocation
&&
permission
!=
Permission
.
activityRecognition
&&
permission
!=
Permission
.
manageExternalStorage
;
}
else
{
return
permission
!=
Permission
.
unknown
&&
permission
!=
Permission
.
mediaLibrary
&&
permission
!=
Permission
.
photos
&&
permission
!=
Permission
.
reminders
;
}
})
.
map
((
permission
)
=>
PermissionWidget
(
permission
))
.
toList
()),
);
}
}
permission_handler/example/lib/plugin_example/permission_widget.dart
deleted
100644 → 0
View file @
39caf3c3
import
'package:flutter/material.dart'
;
import
'package:permission_handler/permission_handler.dart'
;
/// Permission widget which displays a permission and allows users to request
/// the permissions.
class
PermissionWidget
extends
StatefulWidget
{
/// Constructs a [PermissionWidget] for the supplied [Permission].
const
PermissionWidget
(
this
.
_permission
);
final
Permission
_permission
;
@override
_PermissionState
createState
()
=>
_PermissionState
(
_permission
);
}
class
_PermissionState
extends
State
<
PermissionWidget
>
{
_PermissionState
(
this
.
_permission
);
final
Permission
_permission
;
PermissionStatus
_permissionStatus
=
PermissionStatus
.
denied
;
@override
void
initState
()
{
super
.
initState
();
_listenForPermissionStatus
();
}
void
_listenForPermissionStatus
()
async
{
final
status
=
await
_permission
.
status
;
setState
(()
=>
_permissionStatus
=
status
);
}
Color
getPermissionColor
()
{
switch
(
_permissionStatus
)
{
case
PermissionStatus
.
denied
:
return
Colors
.
red
;
case
PermissionStatus
.
granted
:
return
Colors
.
green
;
case
PermissionStatus
.
limited
:
return
Colors
.
orange
;
default
:
return
Colors
.
grey
;
}
}
@override
Widget
build
(
BuildContext
context
)
{
return
ListTile
(
title:
Text
(
_permission
.
toString
(),
style:
Theme
.
of
(
context
).
textTheme
.
bodyText1
,
),
subtitle:
Text
(
_permissionStatus
.
toString
(),
style:
TextStyle
(
color:
getPermissionColor
()),
),
trailing:
IconButton
(
icon:
const
Icon
(
Icons
.
info
,
color:
Colors
.
white
,
),
onPressed:
()
{
checkServiceStatus
(
context
,
_permission
);
}),
onTap:
()
{
requestPermission
(
_permission
);
},
);
}
void
checkServiceStatus
(
BuildContext
context
,
Permission
permission
)
async
{
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
SnackBar
(
content:
Text
((
await
permission
.
status
).
toString
()),
));
}
Future
<
void
>
requestPermission
(
Permission
permission
)
async
{
final
status
=
await
permission
.
request
();
setState
(()
{
print
(
status
);
_permissionStatus
=
status
;
print
(
_permissionStatus
);
});
}
}
permission_handler/example/lib/template/globals.dart
deleted
100644 → 0
View file @
39caf3c3
import
'dart:core'
;
import
'package:flutter/material.dart'
;
import
'../plugin_example/permission_list.dart'
;
import
'info_page.dart'
;
/// The name of the plugin, which will be displayed throughout the example App.
const
String
pluginName
=
'Permission Handler'
;
/// Returns Github URL, which is shown in the [InfoPage].
const
String
githubURL
=
'https://github.com/Baseflow/flutter-permission-handler'
;
/// Returns Baseflow URL, which is shown in the [InfoPage].
const
String
baseflowURL
=
'https://baseflow.com'
;
/// Returns pub.dev URL, which is shown in the [InfoPage].
const
String
pubDevURL
=
'https://pub.dev/packages/permission_handler'
;
/// [EdgeInsets] to define horizontal padding throughout the application.
const
EdgeInsets
defaultHorizontalPadding
=
EdgeInsets
.
symmetric
(
horizontal:
24
);
/// [EdgeInsets] to define vertical padding throughout the application.
const
EdgeInsets
defaultVerticalPadding
=
EdgeInsets
.
symmetric
(
vertical:
24
);
/// Returns a [List] with [IconData] to show in the [AppHome] [AppBar].
final
List
<
IconData
>
icons
=
[
Icons
.
list
,
Icons
.
info_outline
,
];
/// Returns a [List] with [Widget]s to construct pages in the [AppBar].
final
List
<
Widget
>
pages
=
[
PermissionList
(),
InfoPage
(),
];
permission_handler/example/lib/template/info_page.dart
deleted
100644 → 0
View file @
39caf3c3
import
'package:flutter/material.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:url_launcher/url_launcher.dart'
;
import
'globals.dart'
;
/// [StatelessWidget] displaying information about Baseflow
class
InfoPage
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
SizedBox
.
expand
(
child:
Align
(
alignment:
Alignment
.
bottomCenter
,
child:
SingleChildScrollView
(
child:
Padding
(
padding:
defaultHorizontalPadding
+
defaultVerticalPadding
,
child:
Column
(
mainAxisSize:
MainAxisSize
.
max
,
mainAxisAlignment:
MainAxisAlignment
.
end
,
children:
<
Widget
>[
Align
(
alignment:
Alignment
.
centerLeft
,
child:
Image
.
asset
(
'res/images/poweredByBaseflowLogoLight@3x.png'
,
width:
250
,
alignment:
Alignment
.
centerLeft
,
),
),
const
Padding
(
padding:
EdgeInsets
.
symmetric
(
vertical:
24
),
),
Text
(
'This app showcases the possibilities of the
$pluginName
'
'plugin, powered by Baseflow. '
'This plugin is available as open source project on Github. '
'
\n\n
'
'Need help with integrating functionalities within your own '
'apps? Contact us at hello@baseflow.com'
,
style:
Theme
.
of
(
context
).
textTheme
.
bodyText1
,
),
const
Padding
(
padding:
EdgeInsets
.
symmetric
(
vertical:
8
),
),
_launcherRaisedButton
(
'Find us on Github'
,
githubURL
,
context
,
),
_launcherRaisedButton
(
'Find us on pub.dev'
,
pubDevURL
,
context
,
),
_launcherRaisedButton
(
'Visit baseflow.com'
,
baseflowURL
,
context
,
),
const
Padding
(
padding:
EdgeInsets
.
only
(
bottom:
30
),
),
],
),
),
),
),
);
}
Widget
_launcherRaisedButton
(
String
text
,
String
url
,
BuildContext
context
)
{
return
Container
(
width:
MediaQuery
.
of
(
context
).
size
.
width
,
height:
50
,
margin:
const
EdgeInsets
.
only
(
top:
24.0
),
alignment:
Alignment
.
center
,
child:
SizedBox
.
expand
(
child:
ElevatedButton
(
style:
ElevatedButton
.
styleFrom
(
padding:
const
EdgeInsets
.
all
(
8
),
shape:
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
circular
(
30.0
),
),
),
child:
Text
(
text
),
onPressed:
()
=>
_launchURL
(
url
),
),
),
);
}
Future
<
void
>
_launchURL
(
String
url
)
async
{
if
(
await
canLaunch
(
url
))
{
await
launch
(
url
);
}
else
{
throw
'Could not launch
$url
'
;
}
}
}
permission_handler/example/pubspec.yaml
View file @
a6a2049a
...
@@ -5,6 +5,10 @@ environment:
...
@@ -5,6 +5,10 @@ environment:
sdk
:
"
>=2.12.0-259.9.beta
<3.0.0"
sdk
:
"
>=2.12.0-259.9.beta
<3.0.0"
dependencies
:
dependencies
:
baseflow_plugin_template
:
git
:
url
:
git://github.com/Baseflow/baseflow_plugin_template.git
ref
:
v2.0.0-nullsafety
flutter
:
flutter
:
sdk
:
flutter
sdk
:
flutter
...
@@ -23,4 +27,6 @@ flutter:
...
@@ -23,4 +27,6 @@ flutter:
assets
:
assets
:
-
res/images/baseflow_logo_def_light-02.png
-
res/images/baseflow_logo_def_light-02.png
-
res/images/poweredByBaseflowLogoLight@3x.png
-
res/images/poweredByBaseflowLogoLight@3x.png
-
packages/baseflow_plugin_template/logo.png
-
packages/baseflow_plugin_template/poweredByBaseflow.png
permission_handler/pubspec.yaml
View file @
a6a2049a
name
:
permission_handler
name
:
permission_handler
description
:
Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.
description
:
Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.
version
:
7.1.
0
version
:
7.1.
1
homepage
:
https://github.com/baseflowit/flutter-permission-handler
homepage
:
https://github.com/baseflowit/flutter-permission-handler
flutter
:
flutter
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment