Comment out background_fetch experiment

Google no longer seems to allow me to update GitJournal with the
GET_TASKS permission which is required by background_fetch.

https://github.com/transistorsoft/react-native-background-fetch/issues/182
This commit is contained in:
Vishesh Handa
2021-11-07 22:07:10 +01:00
parent 99de134cc0
commit 235e20a941
4 changed files with 142 additions and 151 deletions

View File

@ -26,7 +26,7 @@ allprojects {
maven { maven {
// [required] background_fetch // [required] background_fetch
url "${project(':background_fetch').projectDir}/libs" // url "${project(':background_fetch').projectDir}/libs"
} }
} }
} }

View File

@ -4,160 +4,160 @@
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
*/ */
import 'dart:async'; // import 'dart:async';
import 'package:flutter/material.dart'; // import 'package:flutter/material.dart';
import 'package:background_fetch/background_fetch.dart'; // import 'package:background_fetch/background_fetch.dart';
// [Android-only] This "Headless Task" is run when the Android app // [Android-only] This "Headless Task" is run when the Android app
// is terminated with enableHeadless: true // is terminated with enableHeadless: true
void backgroundFetchHeadlessTask(HeadlessTask task) async { // void backgroundFetchHeadlessTask(HeadlessTask task) async {
String taskId = task.taskId; // String taskId = task.taskId;
bool isTimeout = task.timeout; // bool isTimeout = task.timeout;
if (isTimeout) { // if (isTimeout) {
// This task has exceeded its allowed running-time. // // This task has exceeded its allowed running-time.
// You must stop what you're doing and immediately .finish(taskId) // // You must stop what you're doing and immediately .finish(taskId)
print("[BackgroundFetch] Headless task timed-out: $taskId"); // print("[BackgroundFetch] Headless task timed-out: $taskId");
BackgroundFetch.finish(taskId); // BackgroundFetch.finish(taskId);
return; // return;
} // }
print('[BackgroundFetch] Headless event received.'); // print('[BackgroundFetch] Headless event received.');
// Do your work here... // // Do your work here...
BackgroundFetch.finish(taskId); // BackgroundFetch.finish(taskId);
} // }
void main() { // void main() {
// Enable integration testing with the Flutter Driver extension. // // Enable integration testing with the Flutter Driver extension.
// See https://flutter.io/testing/ for more info. // // See https://flutter.io/testing/ for more info.
runApp(MyApp()); // runApp(MyApp());
// Register to receive BackgroundFetch events after app is terminated. // // Register to receive BackgroundFetch events after app is terminated.
// Requires {stopOnTerminate: false, enableHeadless: true} // // Requires {stopOnTerminate: false, enableHeadless: true}
BackgroundFetch.registerHeadlessTask(backgroundFetchHeadlessTask); // BackgroundFetch.registerHeadlessTask(backgroundFetchHeadlessTask);
} // }
class MyApp extends StatefulWidget { // class MyApp extends StatefulWidget {
@override // @override
_MyAppState createState() => _MyAppState(); // _MyAppState createState() => _MyAppState();
} // }
class _MyAppState extends State<MyApp> { // class _MyAppState extends State<MyApp> {
bool _enabled = true; // bool _enabled = true;
int _status = 0; // int _status = 0;
final List<DateTime> _events = []; // final List<DateTime> _events = [];
@override // @override
void initState() { // void initState() {
super.initState(); // super.initState();
initPlatformState(); // initPlatformState();
} // }
// Platform messages are asynchronous, so we initialize in an async method. // // Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async { // Future<void> initPlatformState() async {
// Configure BackgroundFetch. // // Configure BackgroundFetch.
int status = await BackgroundFetch.configure( // int status = await BackgroundFetch.configure(
BackgroundFetchConfig( // BackgroundFetchConfig(
minimumFetchInterval: 15, // minimumFetchInterval: 15,
stopOnTerminate: false, // stopOnTerminate: false,
enableHeadless: true, // enableHeadless: true,
requiresBatteryNotLow: false, // requiresBatteryNotLow: false,
requiresCharging: false, // requiresCharging: false,
requiresStorageNotLow: false, // requiresStorageNotLow: false,
requiresDeviceIdle: false, // requiresDeviceIdle: false,
requiredNetworkType: NetworkType.NONE), (String taskId) async { // requiredNetworkType: NetworkType.NONE), (String taskId) async {
// <-- Event handler // // <-- Event handler
// This is the fetch-event callback. // // This is the fetch-event callback.
print("[BackgroundFetch] Event received $taskId"); // print("[BackgroundFetch] Event received $taskId");
setState(() { // setState(() {
_events.insert(0, DateTime.now()); // _events.insert(0, DateTime.now());
}); // });
// IMPORTANT: You must signal completion of your task or the OS can punish your app // // IMPORTANT: You must signal completion of your task or the OS can punish your app
// for taking too long in the background. // // for taking too long in the background.
BackgroundFetch.finish(taskId); // BackgroundFetch.finish(taskId);
}, (String taskId) async { // }, (String taskId) async {
// <-- Task timeout handler. // // <-- Task timeout handler.
// This task has exceeded its allowed running-time. You must stop what you're doing and immediately .finish(taskId) // // This task has exceeded its allowed running-time. You must stop what you're doing and immediately .finish(taskId)
print("[BackgroundFetch] TASK TIMEOUT taskId: $taskId"); // print("[BackgroundFetch] TASK TIMEOUT taskId: $taskId");
BackgroundFetch.finish(taskId); // BackgroundFetch.finish(taskId);
}); // });
print('[BackgroundFetch] configure success: $status'); // print('[BackgroundFetch] configure success: $status');
setState(() { // setState(() {
_status = status; // _status = status;
}); // });
// If the widget was removed from the tree while the asynchronous platform // // If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling // // message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance. // // setState to update our non-existent appearance.
if (!mounted) return; // if (!mounted) return;
} // }
void _onClickEnable(enabled) { // void _onClickEnable(enabled) {
setState(() { // setState(() {
_enabled = enabled; // _enabled = enabled;
}); // });
if (enabled) { // if (enabled) {
BackgroundFetch.start().then((int status) { // BackgroundFetch.start().then((int status) {
print('[BackgroundFetch] start success: $status'); // print('[BackgroundFetch] start success: $status');
}).catchError((e) { // }).catchError((e) {
print('[BackgroundFetch] start FAILURE: $e'); // print('[BackgroundFetch] start FAILURE: $e');
}); // });
} else { // } else {
BackgroundFetch.stop().then((int status) { // BackgroundFetch.stop().then((int status) {
print('[BackgroundFetch] stop success: $status'); // print('[BackgroundFetch] stop success: $status');
}); // });
} // }
} // }
void _onClickStatus() async { // void _onClickStatus() async {
int status = await BackgroundFetch.status; // int status = await BackgroundFetch.status;
print('[BackgroundFetch] status: $status'); // print('[BackgroundFetch] status: $status');
setState(() { // setState(() {
_status = status; // _status = status;
}); // });
} // }
@override // @override
Widget build(BuildContext context) { // Widget build(BuildContext context) {
return MaterialApp( // return MaterialApp(
home: Scaffold( // home: Scaffold(
appBar: AppBar( // appBar: AppBar(
title: const Text('BackgroundFetch Example', // title: const Text('BackgroundFetch Example',
style: TextStyle(color: Colors.black)), // style: TextStyle(color: Colors.black)),
backgroundColor: Colors.amberAccent, // backgroundColor: Colors.amberAccent,
actions: <Widget>[ // actions: <Widget>[
Switch(value: _enabled, onChanged: _onClickEnable), // Switch(value: _enabled, onChanged: _onClickEnable),
]), // ]),
body: Container( // body: Container(
color: Colors.black, // color: Colors.black,
child: ListView.builder( // child: ListView.builder(
itemCount: _events.length, // itemCount: _events.length,
itemBuilder: (BuildContext context, int index) { // itemBuilder: (BuildContext context, int index) {
DateTime timestamp = _events[index]; // DateTime timestamp = _events[index];
return InputDecorator( // return InputDecorator(
decoration: const InputDecoration( // decoration: const InputDecoration(
contentPadding: // contentPadding:
EdgeInsets.only(left: 10.0, top: 10.0, bottom: 0.0), // EdgeInsets.only(left: 10.0, top: 10.0, bottom: 0.0),
labelStyle: TextStyle( // labelStyle: TextStyle(
color: Colors.amberAccent, fontSize: 20.0), // color: Colors.amberAccent, fontSize: 20.0),
labelText: "[background fetch event]"), // labelText: "[background fetch event]"),
child: Text(timestamp.toString(), // child: Text(timestamp.toString(),
style: const TextStyle( // style: const TextStyle(
color: Colors.white, fontSize: 16.0))); // color: Colors.white, fontSize: 16.0)));
}), // }),
), // ),
bottomNavigationBar: BottomAppBar( // bottomNavigationBar: BottomAppBar(
child: Row(children: <Widget>[ // child: Row(children: <Widget>[
ElevatedButton( // ElevatedButton(
onPressed: _onClickStatus, child: const Text('Status')), // onPressed: _onClickStatus, child: const Text('Status')),
Container( // Container(
child: Text("$_status"), // child: Text("$_status"),
margin: const EdgeInsets.only(left: 20.0)) // margin: const EdgeInsets.only(left: 20.0))
])), // ])),
), // ),
); // );
} // }
} // }
// Stuff to be saved - // Stuff to be saved -
// (gitRepo, remoteName, lastSyncedWhen, lastError) // (gitRepo, remoteName, lastSyncedWhen, lastError)

View File

@ -78,15 +78,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.0.0-nullsafety.0" version: "3.0.0-nullsafety.0"
background_fetch:
dependency: "direct main"
description:
path: "."
ref: HEAD
resolved-ref: "724a13feeead45dcc491a9d52f867bf6f9c86d50"
url: "https://github.com/Fishbowler/flutter_background_fetch.git"
source: git
version: "1.0.1"
badges: badges:
dependency: "direct main" dependency: "direct main"
description: description:

View File

@ -96,8 +96,8 @@ dependencies:
url: https://github.com/NearHuscarl/flutter_login.git url: https://github.com/NearHuscarl/flutter_login.git
ref: develop ref: develop
android_external_storage: ^0.1.0 android_external_storage: ^0.1.0
background_fetch: # background_fetch:
git: https://github.com/Fishbowler/flutter_background_fetch.git # git: https://github.com/Fishbowler/flutter_background_fetch.git
timeline_tile: ^2.0.0 timeline_tile: ^2.0.0
community_material_icon: ^5.9.55 community_material_icon: ^5.9.55
google_api_availability: ^3.0.1 google_api_availability: ^3.0.1