Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# hivedb_samples
A forked version of Hive DB samples.

Updated with latest dependencies.
24 changes: 22 additions & 2 deletions backup_restore_books/.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,27 @@
# This file should be version controlled and should not be manually edited.

version:
revision: 8af6b2f038c1172e61d418869363a28dffec3cb4
channel: stable
revision: "ff5b5b5fa6f35b717667719ddfdb1521d8bdd05a"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: ff5b5b5fa6f35b717667719ddfdb1521d8bdd05a
base_revision: ff5b5b5fa6f35b717667719ddfdb1521d8bdd05a
- platform: web
create_revision: ff5b5b5fa6f35b717667719ddfdb1521d8bdd05a
base_revision: ff5b5b5fa6f35b717667719ddfdb1521d8bdd05a

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
28 changes: 28 additions & 0 deletions backup_restore_books/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at https://dart.dev/lints.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
2 changes: 1 addition & 1 deletion backup_restore_books/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>8.0</string>
<string>11.0</string>
</dict>
</plist>
1 change: 1 addition & 0 deletions backup_restore_books/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions backup_restore_books/ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
44 changes: 44 additions & 0 deletions backup_restore_books/ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
16 changes: 8 additions & 8 deletions backup_restore_books/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -135,7 +135,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1020;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -179,10 +179,12 @@
/* Begin PBXShellScriptBuildPhase section */
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand All @@ -193,6 +195,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -241,7 +244,6 @@
/* Begin XCBuildConfiguration section */
249021D3217E4FDB00AE95B9 /* Profile */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -281,7 +283,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -318,7 +320,6 @@
};
97C147031CF9000F007C117D /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -364,7 +365,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand All @@ -374,7 +375,6 @@
};
97C147041CF9000F007C117D /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -414,7 +414,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 4 additions & 0 deletions backup_restore_books/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
44 changes: 24 additions & 20 deletions backup_restore_books/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:path_provider/path_provider.dart';

Expand Down Expand Up @@ -32,17 +31,20 @@ const List<String> books = [
void main() async {
await Hive.initFlutter();
await Hive.openBox<String>(favoritesBox);
runApp(MyApp());
runApp(const MyApp());
}

class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);

@override
_MyAppState createState() => _MyAppState();
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
final _scaffoldKey = GlobalKey<ScaffoldState>();
Box<String> favoriteBooksBox;
// final _scaffoldKey = GlobalKey<ScaffoldState>();
final _scaffoldKey = GlobalKey<ScaffoldMessengerState>();
late Box<String> favoriteBooksBox;

@override
void initState() {
Expand All @@ -52,9 +54,9 @@ class _MyAppState extends State<MyApp> {

Widget getIcon(int index) {
if (favoriteBooksBox.containsKey(index)) {
return Icon(Icons.favorite, color: Colors.red);
return const Icon(Icons.favorite, color: Colors.red);
}
return Icon(Icons.favorite_border);
return const Icon(Icons.favorite_border);
}

void onFavoritePress(int index) {
Expand All @@ -67,13 +69,14 @@ class _MyAppState extends State<MyApp> {

Future<void> createBackup() async {
if (favoriteBooksBox.isEmpty) {
_scaffoldKey.currentState.showSnackBar(
SnackBar(content: Text('Pick a favorite book.')),
_scaffoldKey.currentState?.showSnackBar(
const SnackBar(content: Text('Pick a favorite book.')),
);

return;
}
_scaffoldKey.currentState.showSnackBar(
SnackBar(content: Text('Creating backup...')),
_scaffoldKey.currentState?.showSnackBar(
const SnackBar(content: Text('Creating backup...')),
);
Map<String, String> map = favoriteBooksBox
.toMap()
Expand All @@ -91,24 +94,24 @@ class _MyAppState extends State<MyApp> {
}

Future<Directory> _getDirectory() async {
Directory directory = await getExternalStorageDirectory();
Directory? directory = await getExternalStorageDirectory();
const String pathExt = '/backups/';
Directory newDirectory = Directory(directory.path + pathExt);
Directory newDirectory = Directory(directory!.path + pathExt);
if (await newDirectory.exists() == false) {
return newDirectory.create(recursive: true);
}
return newDirectory;
}

Future<void> restoreBackup() async {
_scaffoldKey.currentState.showSnackBar(
SnackBar(content: Text('Restoring backup...')),
_scaffoldKey.currentState?.showSnackBar(
const SnackBar(content: Text('Restoring backup...')),
);
FilePickerResult result = await FilePicker.platform.pickFiles(
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.any,
);
if (result == null) return;
File file = File(result.files.single.path);
File file = File(result.files.single.path.toString());
favoriteBooksBox.clear();
Map<dynamic, dynamic> map =
jsonDecode(await file.readAsString()) as Map<dynamic, dynamic>;
Expand All @@ -120,21 +123,22 @@ class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
scaffoldMessengerKey: _scaffoldKey,
title: 'Favorite Books with Hive',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: Text('Favorite Books w/ Hive'),
title: const Text('Favorite Books w/ Hive'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.backup),
icon: const Icon(Icons.backup),
onPressed: createBackup,
),
IconButton(
icon: Icon(Icons.restore),
icon: const Icon(Icons.restore),
onPressed: restoreBackup,
),
],
Expand Down
12 changes: 8 additions & 4 deletions backup_restore_books/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ publish_to: "none"
version: 1.0.0

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: '>=2.12.0'

dependencies:
flutter:
sdk: flutter
hive: any
hive_flutter: any
path_provider: ^2.0.0
file_picker: ^4.6.0
path_provider: ^2.1.1
file_picker: ^5.5.0

cupertino_icons: ^1.0.0
cupertino_icons: ^1.0.6

flutter:
uses-material-design: true
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.3
Loading