Add app icon and local notifications

Also add android version
This commit is contained in:
Ricardo Markiewicz
2019-07-09 16:13:04 -03:00
parent 99de6c4ef9
commit 776648b470
35 changed files with 365 additions and 23 deletions
+67
View File
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';
import 'package:rect_getter/rect_getter.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import '../login_state.dart';
import '../utils.dart';
@@ -16,6 +17,7 @@ class HomePage extends StatefulWidget {
}
class _HomePageState extends State<HomePage> {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
var globalKey = RectGetter.createGlobalKey();
Rect buttonRect;
@@ -32,6 +34,8 @@ class _HomePageState extends State<HomePage> {
initialPage: currentPage,
viewportFraction: 0.4,
);
setupNotificationPlugin();
}
Widget _bottomAction(IconData icon, Function callback) {
@@ -209,4 +213,67 @@ class _HomePageState extends State<HomePage> {
),
);
}
void setupNotificationPlugin() {
flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
var initializationSettingsAndroid = new AndroidInitializationSettings('app_icon');
var initializationSettingsIOS = new IOSInitializationSettings(
onDidReceiveLocalNotification: onDidReceiveLocalNotification,
);
var initializationSettings = new InitializationSettings(
initializationSettingsAndroid,
initializationSettingsIOS,
);
flutterLocalNotificationsPlugin.initialize(
initializationSettings,
onSelectNotification: onSelectNotification,
).then((init) {
setupNotification();
});
}
Future onSelectNotification(String payload) async {
if (payload != null) {
debugPrint('notification payload: ' + payload);
}
await Navigator.push(
context,
new MaterialPageRoute(builder: (context) => HomePage()),
);
}
Future onDidReceiveLocalNotification(
int id, String title, String body, String payload) async {
// display a dialog with the notification details, tap ok to go to another page
showDialog(
context: context,
builder: (context) => AlertDialog(
content: Text("Don't forget to add your expenses"),
actions: <Widget>[
FlatButton(
child: Text('Ok'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
));
}
void setupNotification() async {
var time = new Time(16, 11, 0);
var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
'daily-notifications',
'Daily Notifications',
'Daily Notifications');
var iOSPlatformChannelSpecifics = new IOSNotificationDetails();
var platformChannelSpecifics = new NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.showDailyAtTime(0, 'Spend-o-meter',
"Don't forget to add your expenses", time, platformChannelSpecifics);
}
}
+122 -16
View File
@@ -1,29 +1,135 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../login_state.dart';
class LoginPage extends StatelessWidget {
class LoginPage extends StatefulWidget {
@override
_LoginPageState createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
TapGestureRecognizer _recognizer1;
TapGestureRecognizer _recognizer2;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Consumer<LoginState>(
builder: (BuildContext context, LoginState value, Widget child) {
if (value.isLoading()) {
return CircularProgressIndicator();
} else {
return child;
}
},
child: RaisedButton(
child: Text("Sign In"),
onPressed: () {
Provider.of<LoginState>(context).login();
},
),
body: SafeArea(
child: Column(
children: <Widget>[
Expanded(
flex: 1,
child: Container(),
),
Text(
"Spend-o-meter",
style: Theme.of(context).textTheme.display1,
),
Padding(
padding: const EdgeInsets.all(32.0),
child: Image.asset('assets/login_background.png'),
),
Text(
"Your personal finance app",
style: Theme.of(context).textTheme.caption,
),
Expanded(
flex: 1,
child: Container(),
),
Consumer<LoginState>(
builder: (BuildContext context, LoginState value, Widget child) {
if (value.isLoading()) {
return CircularProgressIndicator();
} else {
return child;
}
},
child: RaisedButton(
child: Text("Sign in with Google"),
onPressed: () {
Provider.of<LoginState>(context).login();
},
),
),
Expanded(
child: Container(),
),
Padding(
padding: const EdgeInsets.all(32.0),
child: RichText(
textAlign: TextAlign.center,
text: TextSpan(
style: Theme.of(context).textTheme.body1,
text: "To use this app you need to agree to our ",
children: [
TextSpan(
text: "Terms of Service",
recognizer: _recognizer1,
style: Theme.of(context)
.textTheme
.body1
.copyWith(fontWeight: FontWeight.bold),
),
TextSpan(text: " and "),
TextSpan(
text: "Privacy Policy",
recognizer: _recognizer2,
style: Theme.of(context)
.textTheme
.body1
.copyWith(fontWeight: FontWeight.bold),
),
]),
),
)
],
),
),
);
}
@override
void initState() {
super.initState();
_recognizer1 = TapGestureRecognizer()
..onTap = () {
showHelp(
"This service is provided AS IS and has no current warranty on how the"
" data and uptime is managed. The final terms will be released when the final version of the app"
" will be released.");
};
_recognizer2 = TapGestureRecognizer()
..onTap = () {
showHelp(
"All your data is saved anonymously on Firebase Firestore database and will be remain that way."
" no other users will have access to it.");
};
}
@override
void dispose() {
super.dispose();
_recognizer1.dispose();
_recognizer2.dispose();
}
void showHelp(String s) {
showDialog(
context: context,
builder: (context) => AlertDialog(
content: Text(s),
actions: <Widget>[
FlatButton(
child: Text('Ok'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
));
}
}