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
25b10ca8
Unverified
Commit
25b10ca8
authored
May 11, 2021
by
Maurits van Beusekom
Committed by
GitHub
May 11, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #548 from Baseflow/issue/511
Updated example app
parents
7e8064b1
a6a2049a
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 @
25b10ca8
## 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
*
Added support for the "SYSTEM_ALERT_WINDOW" permission on Android.
...
...
permission_handler/example/lib/main.dart
View file @
25b10ca8
import
'package:flutter/material.dart'
;
import
'
package:flutter/widgets.dart
'
;
import
'
template/globals
.dart'
;
import
'
dart:io
'
;
import
'package:baseflow_plugin_template/baseflow_plugin_template.dart'
;
import
'
package:permission_handler/permission_handler
.dart'
;
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
class
BaseflowPluginExample
extends
StatelessWidget
{
/// [MaterialColor] to be used in the app [ThemeData]
final
MaterialColor
themeMaterialColor
=
createMaterialColor
(
const
Color
.
fromRGBO
(
48
,
49
,
60
,
1
));
class
PermissionHandlerWidget
extends
StatefulWidget
{
static
ExamplePage
createPage
()
{
return
ExamplePage
(
Icons
.
location_on
,
(
context
)
=>
PermissionHandlerWidget
());
}
@override
_PermissionHandlerWidgetState
createState
()
=>
_PermissionHandlerWidgetState
();
}
class
_PermissionHandlerWidgetState
extends
State
<
PermissionHandlerWidget
>
{
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
title:
'Baseflow
$pluginName
'
,
theme:
ThemeData
(
accentColor:
Colors
.
white60
,
backgroundColor:
const
Color
.
fromRGBO
(
48
,
49
,
60
,
0.8
),
buttonTheme:
ButtonThemeData
(
buttonColor:
themeMaterialColor
.
shade500
,
disabledColor:
themeMaterialColor
.
withRed
(
200
),
splashColor:
themeMaterialColor
.
shade50
,
textTheme:
ButtonTextTheme
.
primary
,
),
bottomAppBarColor:
const
Color
.
fromRGBO
(
57
,
58
,
71
,
1
),
hintColor:
themeMaterialColor
.
shade500
,
primarySwatch:
createMaterialColor
(
const
Color
.
fromRGBO
(
48
,
49
,
60
,
1
)),
textTheme:
TextTheme
(
bodyText1:
TextStyle
(
color:
Colors
.
white
,
fontSize:
16
,
height:
1.3
,
),
bodyText2:
TextStyle
(
color:
Colors
.
white
,
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'
),
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
&&
permission
!=
Permission
.
systemAlertWindow
;
}
else
{
return
permission
!=
Permission
.
unknown
&&
permission
!=
Permission
.
mediaLibrary
&&
permission
!=
Permission
.
photos
&&
permission
!=
Permission
.
reminders
;
}
})
.
map
((
permission
)
=>
PermissionWidget
(
permission
))
.
toList
()),
);
}
}
/// Creates a [MaterialColor] based on the supplied [Color]
static
MaterialColor
createMaterialColor
(
Color
color
)
{
List
strengths
=
<
double
>[.
05
];
Map
swatch
=
<
int
,
Color
>{};
final
r
=
color
.
red
,
g
=
color
.
green
,
b
=
color
.
blue
;
class
PermissionWidget
extends
StatefulWidget
{
/// Constructs a [PermissionWidget] for the supplied [Permission].
const
PermissionWidget
(
this
.
_permission
);
for
(
var
i
=
1
;
i
<
10
;
i
++)
{
strengths
.
add
(
0.1
*
i
);
}
for
(
var
strength
in
strengths
)
{
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
>);
}
final
Permission
_permission
;
@override
_PermissionState
createState
()
=>
_PermissionState
(
_permission
);
}
/// A Flutter example demonstrating how the [pluginName] plugin could be used
class
AppHome
extends
StatefulWidget
{
/// Constructs the [AppHome] class
AppHome
({
Key
?
key
,
this
.
title
})
:
super
(
key:
key
);
class
_PermissionState
extends
State
<
PermissionWidget
>
{
_PermissionState
(
this
.
_permission
);
/// The [title] of the application, which is shown in the application's
/// title bar.
final
String
?
title
;
final
Permission
_permission
;
PermissionStatus
_permissionStatus
=
PermissionStatus
.
denied
;
@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
>
{
static
final
PageController
_pageController
=
PageController
(
initialPage:
0
);
int
_currentPage
=
0
;
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
Scaffold
(
appBar:
AppBar
(
backgroundColor:
Theme
.
of
(
context
).
bottomAppBarColor
,
title:
Center
(
child:
Image
.
asset
(
'res/images/baseflow_logo_def_light-02.png'
,
width:
140
,
),
),
return
ListTile
(
title:
Text
(
_permission
.
toString
(),
style:
Theme
.
of
(
context
).
textTheme
.
bodyText1
,
),
backgroundColor:
Theme
.
of
(
context
).
backgroundColor
,
body:
PageView
(
controller:
_pageController
,
children:
pages
,
onPageChanged:
(
page
)
{
setState
(()
{
_currentPage
=
page
;
});
},
subtitle:
Text
(
_permissionStatus
.
toString
(),
style:
TextStyle
(
color:
getPermissionColor
()),
),
bottomNavigationBar:
_bottomAppBar
(),
trailing:
IconButton
(
icon:
const
Icon
(
Icons
.
info
,
color:
Colors
.
white
,
),
onPressed:
()
{
checkServiceStatus
(
context
,
_permission
);
}),
onTap:
()
{
requestPermission
(
_permission
);
},
);
}
BottomAppBar
_bottomAppBar
()
{
return
BottomAppBar
(
elevation:
5
,
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
checkServiceStatus
(
BuildContext
context
,
Permission
permission
)
async
{
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
SnackBar
(
content:
Text
((
await
permission
.
status
).
toString
()),
));
}
void
_animateToPage
(
int
page
)
{
_pageController
.
animateToPage
(
page
,
duration:
Duration
(
milliseconds:
200
),
curve:
Curves
.
linear
);
}
Future
<
void
>
requestPermission
(
Permission
permission
)
async
{
final
status
=
await
permission
.
request
();
Color
_bottomAppBarIconColor
(
int
page
)
{
return
_currentPage
==
page
?
Colors
.
white
:
Theme
.
of
(
context
).
accentColor
;
setState
(()
{
print
(
status
);
_permissionStatus
=
status
;
print
(
_permissionStatus
);
});
}
}
permission_handler/example/lib/plugin_example/permission_list.dart
deleted
100644 → 0
View file @
7e8064b1
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 @
7e8064b1
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 @
7e8064b1
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 @
7e8064b1
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 @
25b10ca8
...
...
@@ -5,6 +5,10 @@ environment:
sdk
:
"
>=2.12.0-259.9.beta
<3.0.0"
dependencies
:
baseflow_plugin_template
:
git
:
url
:
git://github.com/Baseflow/baseflow_plugin_template.git
ref
:
v2.0.0-nullsafety
flutter
:
sdk
:
flutter
...
...
@@ -23,4 +27,6 @@ flutter:
assets
:
-
res/images/baseflow_logo_def_light-02.png
-
res/images/poweredByBaseflowLogoLight@3x.png
-
packages/baseflow_plugin_template/logo.png
-
packages/baseflow_plugin_template/poweredByBaseflow.png
permission_handler/pubspec.yaml
View file @
25b10ca8
name
:
permission_handler
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
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