Skip to content

Commit

Permalink
run in background
Browse files Browse the repository at this point in the history
  • Loading branch information
Lysander66 committed Feb 3, 2023
1 parent 1a2d024 commit d19adb2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:io' show Platform, exit;

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_background/flutter_background.dart';
import 'package:get/get.dart';

import 'generated/locales.g.dart';
Expand All @@ -13,6 +14,18 @@ Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await ConfigService.init();

const androidConfig = FlutterBackgroundAndroidConfig(
notificationTitle: 'brook',
notificationText:
'Background notification for keeping the example app running in the background',
notificationImportance: AndroidNotificationImportance.Default,
notificationIcon: AndroidResource(
name: 'background_icon',
defType: 'drawable',
), // Default is ic_launcher from folder mipmap
);
await FlutterBackground.initialize(androidConfig: androidConfig);

// 定时关闭
Future.delayed(const Duration(minutes: 60), () {
// SystemChannels.platform.invokeMethod('SystemNavigator.pop');
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_background:
dependency: "direct main"
description:
name: flutter_background
sha256: "035c31a738509d67ee70bbf174e5aa7db462c371e838ec8259700c5c4e7ca17f"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
flutter_blurhash:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies:
flutter_dotenv: ^5.0.2
audioplayers: ^3.0.0
cached_network_image: ^3.2.3
flutter_background: ^1.2.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit d19adb2

Please sign in to comment.