diff --git a/README.md b/README.md new file mode 100644 index 0000000..c71e02f --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# hivedb_samples +A forked version of Hive DB samples. + +Updated with latest dependencies. diff --git a/backup_restore_books/.metadata b/backup_restore_books/.metadata index ade6bc9..5ad07d3 100644 --- a/backup_restore_books/.metadata +++ b/backup_restore_books/.metadata @@ -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' diff --git a/backup_restore_books/analysis_options.yaml b/backup_restore_books/analysis_options.yaml new file mode 100644 index 0000000..0d29021 --- /dev/null +++ b/backup_restore_books/analysis_options.yaml @@ -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 diff --git a/backup_restore_books/ios/Flutter/AppFrameworkInfo.plist b/backup_restore_books/ios/Flutter/AppFrameworkInfo.plist index 6b4c0f7..4f8d4d2 100644 --- a/backup_restore_books/ios/Flutter/AppFrameworkInfo.plist +++ b/backup_restore_books/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 8.0 + 11.0 diff --git a/backup_restore_books/ios/Flutter/Debug.xcconfig b/backup_restore_books/ios/Flutter/Debug.xcconfig index 592ceee..ec97fc6 100644 --- a/backup_restore_books/ios/Flutter/Debug.xcconfig +++ b/backup_restore_books/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/backup_restore_books/ios/Flutter/Release.xcconfig b/backup_restore_books/ios/Flutter/Release.xcconfig index 592ceee..c4855bf 100644 --- a/backup_restore_books/ios/Flutter/Release.xcconfig +++ b/backup_restore_books/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/backup_restore_books/ios/Podfile b/backup_restore_books/ios/Podfile new file mode 100644 index 0000000..fdcc671 --- /dev/null +++ b/backup_restore_books/ios/Podfile @@ -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 diff --git a/backup_restore_books/ios/Runner.xcodeproj/project.pbxproj b/backup_restore_books/ios/Runner.xcodeproj/project.pbxproj index 7c5c715..1421bff 100644 --- a/backup_restore_books/ios/Runner.xcodeproj/project.pbxproj +++ b/backup_restore_books/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -135,7 +135,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1020; + LastUpgradeCheck = 1430; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -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 = ( @@ -193,6 +195,7 @@ }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -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; @@ -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; @@ -318,7 +320,6 @@ }; 97C147031CF9000F007C117D /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -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; @@ -374,7 +375,6 @@ }; 97C147041CF9000F007C117D /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -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; diff --git a/backup_restore_books/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/backup_restore_books/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 1d526a1..919434a 100644 --- a/backup_restore_books/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/backup_restore_books/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/backup_restore_books/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/backup_restore_books/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index a28140c..b52b2e6 100644 --- a/backup_restore_books/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/backup_restore_books/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ UIViewControllerBasedStatusBarAppearance + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + diff --git a/backup_restore_books/lib/main.dart b/backup_restore_books/lib/main.dart index ee13ac6..a07684a 100644 --- a/backup_restore_books/lib/main.dart +++ b/backup_restore_books/lib/main.dart @@ -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'; @@ -32,17 +31,20 @@ const List books = [ void main() async { await Hive.initFlutter(); await Hive.openBox(favoritesBox); - runApp(MyApp()); + runApp(const MyApp()); } class MyApp extends StatefulWidget { + const MyApp({Key? key}) : super(key: key); + @override - _MyAppState createState() => _MyAppState(); + State createState() => _MyAppState(); } class _MyAppState extends State { - final _scaffoldKey = GlobalKey(); - Box favoriteBooksBox; + // final _scaffoldKey = GlobalKey(); + final _scaffoldKey = GlobalKey(); + late Box favoriteBooksBox; @override void initState() { @@ -52,9 +54,9 @@ class _MyAppState extends State { 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) { @@ -67,13 +69,14 @@ class _MyAppState extends State { Future 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 map = favoriteBooksBox .toMap() @@ -91,9 +94,9 @@ class _MyAppState extends State { } Future _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); } @@ -101,14 +104,14 @@ class _MyAppState extends State { } Future 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 map = jsonDecode(await file.readAsString()) as Map; @@ -120,6 +123,7 @@ class _MyAppState extends State { @override Widget build(BuildContext context) { return MaterialApp( + scaffoldMessengerKey: _scaffoldKey, title: 'Favorite Books with Hive', theme: ThemeData( primarySwatch: Colors.blue, @@ -127,14 +131,14 @@ class _MyAppState extends State { home: Scaffold( key: _scaffoldKey, appBar: AppBar( - title: Text('Favorite Books w/ Hive'), + title: const Text('Favorite Books w/ Hive'), actions: [ IconButton( - icon: Icon(Icons.backup), + icon: const Icon(Icons.backup), onPressed: createBackup, ), IconButton( - icon: Icon(Icons.restore), + icon: const Icon(Icons.restore), onPressed: restoreBackup, ), ], diff --git a/backup_restore_books/pubspec.yaml b/backup_restore_books/pubspec.yaml index cc57279..e82113a 100644 --- a/backup_restore_books/pubspec.yaml +++ b/backup_restore_books/pubspec.yaml @@ -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 diff --git a/backup_restore_books/test/widget_test.dart b/backup_restore_books/test/widget_test.dart new file mode 100644 index 0000000..9d73cfd --- /dev/null +++ b/backup_restore_books/test/widget_test.dart @@ -0,0 +1,30 @@ +// This is a basic Flutter widget test. +// +// To perform an interaction with a widget in your test, use the WidgetTester +// utility in the flutter_test package. For example, you can send tap and scroll +// gestures. You can also use WidgetTester to find child widgets in the widget +// tree, read text, and verify that the values of widget properties are correct. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:backup_restore_books/main.dart'; + +void main() { + testWidgets('Counter increments smoke test', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(const MyApp()); + + // Verify that our counter starts at 0. + expect(find.text('0'), findsOneWidget); + expect(find.text('1'), findsNothing); + + // Tap the '+' icon and trigger a frame. + await tester.tap(find.byIcon(Icons.add)); + await tester.pump(); + + // Verify that our counter has incremented. + expect(find.text('0'), findsNothing); + expect(find.text('1'), findsOneWidget); + }); +} diff --git a/backup_restore_books/web/favicon.png b/backup_restore_books/web/favicon.png new file mode 100644 index 0000000..8aaa46a Binary files /dev/null and b/backup_restore_books/web/favicon.png differ diff --git a/backup_restore_books/web/icons/Icon-192.png b/backup_restore_books/web/icons/Icon-192.png new file mode 100644 index 0000000..b749bfe Binary files /dev/null and b/backup_restore_books/web/icons/Icon-192.png differ diff --git a/backup_restore_books/web/icons/Icon-512.png b/backup_restore_books/web/icons/Icon-512.png new file mode 100644 index 0000000..88cfd48 Binary files /dev/null and b/backup_restore_books/web/icons/Icon-512.png differ diff --git a/backup_restore_books/web/icons/Icon-maskable-192.png b/backup_restore_books/web/icons/Icon-maskable-192.png new file mode 100644 index 0000000..eb9b4d7 Binary files /dev/null and b/backup_restore_books/web/icons/Icon-maskable-192.png differ diff --git a/backup_restore_books/web/icons/Icon-maskable-512.png b/backup_restore_books/web/icons/Icon-maskable-512.png new file mode 100644 index 0000000..d69c566 Binary files /dev/null and b/backup_restore_books/web/icons/Icon-maskable-512.png differ diff --git a/backup_restore_books/web/index.html b/backup_restore_books/web/index.html new file mode 100644 index 0000000..3f961b4 --- /dev/null +++ b/backup_restore_books/web/index.html @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + backup_restore_books + + + + + + + + + + diff --git a/backup_restore_books/web/manifest.json b/backup_restore_books/web/manifest.json new file mode 100644 index 0000000..716ef2c --- /dev/null +++ b/backup_restore_books/web/manifest.json @@ -0,0 +1,35 @@ +{ + "name": "backup_restore_books", + "short_name": "backup_restore_books", + "start_url": ".", + "display": "standalone", + "background_color": "#0175C2", + "theme_color": "#0175C2", + "description": "A new Flutter project.", + "orientation": "portrait-primary", + "prefer_related_applications": false, + "icons": [ + { + "src": "icons/Icon-192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "icons/Icon-512.png", + "sizes": "512x512", + "type": "image/png" + }, + { + "src": "icons/Icon-maskable-192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "maskable" + }, + { + "src": "icons/Icon-maskable-512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "maskable" + } + ] +} diff --git a/contacts/.metadata b/contacts/.metadata index 361e1e4..5ad07d3 100644 --- a/contacts/.metadata +++ b/contacts/.metadata @@ -4,7 +4,27 @@ # This file should be version controlled and should not be manually edited. version: - revision: 18cd7a3601bcffb36fdf2f679f763b5e827c2e8e - channel: beta + 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' diff --git a/contacts/analysis_options.yaml b/contacts/analysis_options.yaml new file mode 100644 index 0000000..0d29021 --- /dev/null +++ b/contacts/analysis_options.yaml @@ -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 diff --git a/contacts/ios/Flutter/Debug.xcconfig b/contacts/ios/Flutter/Debug.xcconfig index 592ceee..ec97fc6 100644 --- a/contacts/ios/Flutter/Debug.xcconfig +++ b/contacts/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/contacts/ios/Flutter/Release.xcconfig b/contacts/ios/Flutter/Release.xcconfig index 592ceee..c4855bf 100644 --- a/contacts/ios/Flutter/Release.xcconfig +++ b/contacts/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/contacts/ios/Podfile b/contacts/ios/Podfile new file mode 100644 index 0000000..fdcc671 --- /dev/null +++ b/contacts/ios/Podfile @@ -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 diff --git a/contacts/lib/main.dart b/contacts/lib/main.dart index a8a847e..d641306 100644 --- a/contacts/lib/main.dart +++ b/contacts/lib/main.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:hive/hive.dart'; import 'package:hive_flutter/hive_flutter.dart'; part 'main.g.dart'; @@ -10,13 +9,14 @@ const String contactsBoxName = "contacts"; @HiveType(typeId: 1) enum Relationship { @HiveField(0) - Family, + family, @HiveField(1) - Friend, + friend, } + const relationships = { - Relationship.Family: "Family", - Relationship.Friend: "Friend", + Relationship.family: "Family", + Relationship.friend: "Friend", }; @HiveType(typeId: 0) @@ -38,32 +38,35 @@ void main() async { Hive.registerAdapter(ContactAdapter()); Hive.registerAdapter(RelationshipAdapter()); await Hive.openBox(contactsBoxName); - runApp(MyApp()); + runApp(const MyApp()); } class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { - Widget _buildDivider() => const SizedBox(height: 5); + Widget buildDivider() => const SizedBox(height: 5); return MaterialApp( title: 'Contacts App', home: Scaffold( appBar: AppBar( - title: Text('Contacts App with Hive'), + title: const Text('Contacts App with Hive'), ), body: ValueListenableBuilder( valueListenable: Hive.box(contactsBoxName).listenable(), builder: (context, Box box, _) { - if (box.values.isEmpty) - return Center( + if (box.values.isEmpty) { + return const Center( child: Text("No contacts"), ); + } return ListView.builder( itemCount: box.length, itemBuilder: (context, index) { - Contact c = box.getAt(index); - String relationship = relationships[c.relationship]; + Contact? c = box.getAt(index); + String? relationship = relationships[c?.relationship]; return InkWell( onLongPress: () { showDialog( @@ -71,15 +74,15 @@ class MyApp extends StatelessWidget { barrierDismissible: true, builder: (_) => AlertDialog( content: Text( - "Do you want to delete ${c.name}?", + "Do you want to delete ${c?.name}?", ), actions: [ - FlatButton( - child: Text("No"), + TextButton( + child: const Text("No"), onPressed: () => Navigator.of(context).pop(), ), - FlatButton( - child: Text("Yes"), + TextButton( + child: const Text("Yes"), onPressed: () async { Navigator.of(context).pop(); await box.deleteAt(index); @@ -95,15 +98,15 @@ class MyApp extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - _buildDivider(), - Text(c.name), - _buildDivider(), + buildDivider(), + Text(c!.name), + buildDivider(), Text(c.phoneNumber), - _buildDivider(), + buildDivider(), Text("Age: ${c.age}"), - _buildDivider(), + buildDivider(), Text("Relationship: $relationship"), - _buildDivider(), + buildDivider(), ], ), ), @@ -116,7 +119,7 @@ class MyApp extends StatelessWidget { floatingActionButton: Builder( builder: (context) { return FloatingActionButton( - child: Icon(Icons.add), + child: const Icon(Icons.add), onPressed: () { Navigator.of(context).push( MaterialPageRoute(builder: (context) => AddContact()), @@ -133,18 +136,20 @@ class MyApp extends StatelessWidget { class AddContact extends StatefulWidget { final formKey = GlobalKey(); + AddContact({Key? key}) : super(key: key); + @override - _AddContactState createState() => _AddContactState(); + State createState() => _AddContactState(); } class _AddContactState extends State { - String name; - int age; - String phoneNumber; - Relationship relationship; + String name = ''; + int age = 0; + String phoneNumber = ''; + Relationship relationship = Relationship.friend; void onFormSubmit() { - if (widget.formKey.currentState.validate()) { + if (widget.formKey.currentState!.validate()) { Box contactsBox = Hive.box(contactsBoxName); contactsBox.add(Contact(name, age, phoneNumber, relationship)); Navigator.of(context).pop(); @@ -202,20 +207,20 @@ class _AddContactState extends State { items: relationships.keys.map((Relationship value) { return DropdownMenuItem( value: value, - child: Text(relationships[value]), + child: Text(relationships[value]!), ); }).toList(), value: relationship, - hint: Text("Relationship"), + hint: const Text("Relationship"), onChanged: (value) { setState(() { - relationship = value; + relationship = value as Relationship; }); }, ), OutlinedButton( - child: Text("Submit"), onPressed: onFormSubmit, + child: const Text("Submit"), ), ], ), diff --git a/contacts/lib/main.g.dart b/contacts/lib/main.g.dart index 8611275..b6dec7b 100644 --- a/contacts/lib/main.g.dart +++ b/contacts/lib/main.g.dart @@ -6,44 +6,15 @@ part of 'main.dart'; // TypeAdapterGenerator // ************************************************************************** -class RelationshipAdapter extends TypeAdapter { - @override - final typeId = 1; - - @override - Relationship read(BinaryReader reader) { - switch (reader.readByte()) { - case 0: - return Relationship.Family; - case 1: - return Relationship.Friend; - default: - return null; - } - } - - @override - void write(BinaryWriter writer, Relationship obj) { - switch (obj) { - case Relationship.Family: - writer.writeByte(0); - break; - case Relationship.Friend: - writer.writeByte(1); - break; - } - } -} - class ContactAdapter extends TypeAdapter { @override - final typeId = 0; + final int typeId = 0; @override Contact read(BinaryReader reader) { - var numOfFields = reader.readByte(); - var fields = { - for (var i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), + final numOfFields = reader.readByte(); + final fields = { + for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), }; return Contact( fields[0] as String, @@ -66,4 +37,53 @@ class ContactAdapter extends TypeAdapter { ..writeByte(3) ..write(obj.phoneNumber); } + + @override + int get hashCode => typeId.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is ContactAdapter && + runtimeType == other.runtimeType && + typeId == other.typeId; +} + +class RelationshipAdapter extends TypeAdapter { + @override + final int typeId = 1; + + @override + Relationship read(BinaryReader reader) { + switch (reader.readByte()) { + case 0: + return Relationship.family; + case 1: + return Relationship.friend; + default: + return Relationship.family; + } + } + + @override + void write(BinaryWriter writer, Relationship obj) { + switch (obj) { + case Relationship.family: + writer.writeByte(0); + break; + case Relationship.friend: + writer.writeByte(1); + break; + } + } + + @override + int get hashCode => typeId.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is RelationshipAdapter && + runtimeType == other.runtimeType && + typeId == other.typeId; } diff --git a/contacts/pubspec.yaml b/contacts/pubspec.yaml index e9cb19e..3a49193 100644 --- a/contacts/pubspec.yaml +++ b/contacts/pubspec.yaml @@ -1,10 +1,10 @@ -name: contacts_hive +name: contacts description: A HiveDB sample project that demonstrates TypeAdapter functionality. version: 1.0.0+1 environment: - sdk: ">=2.6.0 <3.0.0" + sdk: '>=2.12.0' dependencies: flutter: @@ -14,7 +14,11 @@ dependencies: dev_dependencies: hive_generator: any - build_runner: ^2.1.0 + build_runner: ^2.4.6 + flutter_test: + sdk: flutter + flutter_lints: ^2.0.3 + flutter: uses-material-design: true diff --git a/contacts/test/widget_test.dart b/contacts/test/widget_test.dart new file mode 100644 index 0000000..f73427e --- /dev/null +++ b/contacts/test/widget_test.dart @@ -0,0 +1,30 @@ +// This is a basic Flutter widget test. +// +// To perform an interaction with a widget in your test, use the WidgetTester +// utility in the flutter_test package. For example, you can send tap and scroll +// gestures. You can also use WidgetTester to find child widgets in the widget +// tree, read text, and verify that the values of widget properties are correct. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:contacts/main.dart'; + +void main() { + testWidgets('Counter increments smoke test', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(const MyApp()); + + // Verify that our counter starts at 0. + expect(find.text('0'), findsOneWidget); + expect(find.text('1'), findsNothing); + + // Tap the '+' icon and trigger a frame. + await tester.tap(find.byIcon(Icons.add)); + await tester.pump(); + + // Verify that our counter has incremented. + expect(find.text('0'), findsNothing); + expect(find.text('1'), findsOneWidget); + }); +} diff --git a/contacts/web/favicon.png b/contacts/web/favicon.png new file mode 100644 index 0000000..8aaa46a Binary files /dev/null and b/contacts/web/favicon.png differ diff --git a/contacts/web/icons/Icon-192.png b/contacts/web/icons/Icon-192.png new file mode 100644 index 0000000..b749bfe Binary files /dev/null and b/contacts/web/icons/Icon-192.png differ diff --git a/contacts/web/icons/Icon-512.png b/contacts/web/icons/Icon-512.png new file mode 100644 index 0000000..88cfd48 Binary files /dev/null and b/contacts/web/icons/Icon-512.png differ diff --git a/contacts/web/icons/Icon-maskable-192.png b/contacts/web/icons/Icon-maskable-192.png new file mode 100644 index 0000000..eb9b4d7 Binary files /dev/null and b/contacts/web/icons/Icon-maskable-192.png differ diff --git a/contacts/web/icons/Icon-maskable-512.png b/contacts/web/icons/Icon-maskable-512.png new file mode 100644 index 0000000..d69c566 Binary files /dev/null and b/contacts/web/icons/Icon-maskable-512.png differ diff --git a/contacts/web/index.html b/contacts/web/index.html new file mode 100644 index 0000000..3d4328f --- /dev/null +++ b/contacts/web/index.html @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + contacts + + + + + + + + + + diff --git a/contacts/web/manifest.json b/contacts/web/manifest.json new file mode 100644 index 0000000..fd221ae --- /dev/null +++ b/contacts/web/manifest.json @@ -0,0 +1,35 @@ +{ + "name": "contacts", + "short_name": "contacts", + "start_url": ".", + "display": "standalone", + "background_color": "#0175C2", + "theme_color": "#0175C2", + "description": "A new Flutter project.", + "orientation": "portrait-primary", + "prefer_related_applications": false, + "icons": [ + { + "src": "icons/Icon-192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "icons/Icon-512.png", + "sizes": "512x512", + "type": "image/png" + }, + { + "src": "icons/Icon-maskable-192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "maskable" + }, + { + "src": "icons/Icon-maskable-512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "maskable" + } + ] +} diff --git a/counter/ios/Flutter/Debug.xcconfig b/counter/ios/Flutter/Debug.xcconfig index 592ceee..ec97fc6 100644 --- a/counter/ios/Flutter/Debug.xcconfig +++ b/counter/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/counter/ios/Flutter/Release.xcconfig b/counter/ios/Flutter/Release.xcconfig index 592ceee..c4855bf 100644 --- a/counter/ios/Flutter/Release.xcconfig +++ b/counter/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/counter/ios/Podfile b/counter/ios/Podfile new file mode 100644 index 0000000..fdcc671 --- /dev/null +++ b/counter/ios/Podfile @@ -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 diff --git a/counter/lib/main.dart b/counter/lib/main.dart index 0c73a02..a10c784 100644 --- a/counter/lib/main.dart +++ b/counter/lib/main.dart @@ -1,6 +1,5 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:hive/hive.dart'; import 'package:hive_flutter/hive_flutter.dart'; void main() async { @@ -49,7 +48,7 @@ class MyApp extends StatelessWidget { } class MyHomePage extends StatefulWidget { - const MyHomePage({@required this.title}); + const MyHomePage({required this.title}); final String title; @@ -58,7 +57,7 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - Box _box; + late Box _box; @override void initState() { @@ -87,7 +86,7 @@ class _MyHomePageState extends State { builder: (context, box, _) { return Text( '${box.get('counter', defaultValue: 0)}', - style: Theme.of(context).textTheme.headline4, + style: Theme.of(context).textTheme.headlineMedium, ); }, ) @@ -99,7 +98,7 @@ class _MyHomePageState extends State { children: [ FloatingActionButton( onPressed: () { - _box.put('counter', _box.get('counter', defaultValue: 0) - 1); + _box.put('counter', _box.get('counter', defaultValue: 0)! - 1); }, tooltip: 'Decrement', child: Icon(Icons.remove), @@ -109,7 +108,7 @@ class _MyHomePageState extends State { ), FloatingActionButton( onPressed: () { - _box.put('counter', _box.get('counter', defaultValue: 0) + 1); + _box.put('counter', _box.get('counter', defaultValue: 0)! + 1); }, tooltip: 'Increment', child: Icon(Icons.add), diff --git a/counter/pubspec.yaml b/counter/pubspec.yaml index 6f4c535..8774bec 100644 --- a/counter/pubspec.yaml +++ b/counter/pubspec.yaml @@ -6,7 +6,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev version: 1.0.0 environment: - sdk: ">=2.7.0 <3.0.0" + sdk: '>=2.12.0' dependencies: flutter: @@ -15,11 +15,12 @@ dependencies: hive: any hive_flutter: any - cupertino_icons: ^1.0.0 + cupertino_icons: ^1.0.6 dev_dependencies: flutter_test: sdk: flutter + flutter_lints: ^2.0.3 flutter: uses-material-design: true diff --git a/favorite_books/.metadata b/favorite_books/.metadata index 361e1e4..5ad07d3 100644 --- a/favorite_books/.metadata +++ b/favorite_books/.metadata @@ -4,7 +4,27 @@ # This file should be version controlled and should not be manually edited. version: - revision: 18cd7a3601bcffb36fdf2f679f763b5e827c2e8e - channel: beta + 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' diff --git a/favorite_books/analysis_options.yaml b/favorite_books/analysis_options.yaml new file mode 100644 index 0000000..0d29021 --- /dev/null +++ b/favorite_books/analysis_options.yaml @@ -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 diff --git a/favorite_books/android/build.gradle b/favorite_books/android/build.gradle index ca8c5c0..ff6da8a 100644 --- a/favorite_books/android/build.gradle +++ b/favorite_books/android/build.gradle @@ -26,6 +26,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } diff --git a/favorite_books/ios/Flutter/Debug.xcconfig b/favorite_books/ios/Flutter/Debug.xcconfig index 592ceee..ec97fc6 100644 --- a/favorite_books/ios/Flutter/Debug.xcconfig +++ b/favorite_books/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/favorite_books/ios/Flutter/Release.xcconfig b/favorite_books/ios/Flutter/Release.xcconfig index 592ceee..c4855bf 100644 --- a/favorite_books/ios/Flutter/Release.xcconfig +++ b/favorite_books/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/favorite_books/ios/Podfile b/favorite_books/ios/Podfile new file mode 100644 index 0000000..fdcc671 --- /dev/null +++ b/favorite_books/ios/Podfile @@ -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 diff --git a/favorite_books/lib/main.dart b/favorite_books/lib/main.dart index 9a48bc3..657e3fd 100644 --- a/favorite_books/lib/main.dart +++ b/favorite_books/lib/main.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:hive/hive.dart'; import 'package:hive_flutter/hive_flutter.dart'; const favoritesBox = 'favorite_books'; @@ -26,16 +25,18 @@ const List books = [ void main() async { await Hive.initFlutter(); await Hive.openBox(favoritesBox); - runApp(MyApp()); + runApp(const MyApp()); } class MyApp extends StatefulWidget { + const MyApp({Key? key}) : super(key: key); + @override - _MyAppState createState() => _MyAppState(); + State createState() => _MyAppState(); } class _MyAppState extends State { - Box favoriteBooksBox; + late Box favoriteBooksBox; @override void initState() { @@ -45,9 +46,9 @@ class _MyAppState extends State { 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) { @@ -67,7 +68,7 @@ class _MyAppState extends State { ), home: Scaffold( appBar: AppBar( - title: Text("Favorite Books w/ Hive"), + title: const Text("Favorite Books w/ Hive"), ), body: ValueListenableBuilder( valueListenable: favoriteBooksBox.listenable(), diff --git a/favorite_books/pubspec.yaml b/favorite_books/pubspec.yaml index 3498b82..ad50d8c 100644 --- a/favorite_books/pubspec.yaml +++ b/favorite_books/pubspec.yaml @@ -4,7 +4,7 @@ description: A HiveDB sample project that demonstrates simple use of HiveDB. version: 1.0.0+1 environment: - sdk: '>=2.1.0 <3.0.0' + sdk: '>=2.12.0' dependencies: flutter: @@ -15,6 +15,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter + flutter_lints: ^2.0.3 flutter: uses-material-design: true diff --git a/favorite_books/test/widget_test.dart b/favorite_books/test/widget_test.dart new file mode 100644 index 0000000..3158216 --- /dev/null +++ b/favorite_books/test/widget_test.dart @@ -0,0 +1,30 @@ +// This is a basic Flutter widget test. +// +// To perform an interaction with a widget in your test, use the WidgetTester +// utility in the flutter_test package. For example, you can send tap and scroll +// gestures. You can also use WidgetTester to find child widgets in the widget +// tree, read text, and verify that the values of widget properties are correct. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:favorite_books/main.dart'; + +void main() { + testWidgets('Counter increments smoke test', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(const MyApp()); + + // Verify that our counter starts at 0. + expect(find.text('0'), findsOneWidget); + expect(find.text('1'), findsNothing); + + // Tap the '+' icon and trigger a frame. + await tester.tap(find.byIcon(Icons.add)); + await tester.pump(); + + // Verify that our counter has incremented. + expect(find.text('0'), findsNothing); + expect(find.text('1'), findsOneWidget); + }); +} diff --git a/favorite_books/web/favicon.png b/favorite_books/web/favicon.png new file mode 100644 index 0000000..8aaa46a Binary files /dev/null and b/favorite_books/web/favicon.png differ diff --git a/favorite_books/web/icons/Icon-192.png b/favorite_books/web/icons/Icon-192.png new file mode 100644 index 0000000..b749bfe Binary files /dev/null and b/favorite_books/web/icons/Icon-192.png differ diff --git a/favorite_books/web/icons/Icon-512.png b/favorite_books/web/icons/Icon-512.png new file mode 100644 index 0000000..88cfd48 Binary files /dev/null and b/favorite_books/web/icons/Icon-512.png differ diff --git a/favorite_books/web/icons/Icon-maskable-192.png b/favorite_books/web/icons/Icon-maskable-192.png new file mode 100644 index 0000000..eb9b4d7 Binary files /dev/null and b/favorite_books/web/icons/Icon-maskable-192.png differ diff --git a/favorite_books/web/icons/Icon-maskable-512.png b/favorite_books/web/icons/Icon-maskable-512.png new file mode 100644 index 0000000..d69c566 Binary files /dev/null and b/favorite_books/web/icons/Icon-maskable-512.png differ diff --git a/favorite_books/web/index.html b/favorite_books/web/index.html new file mode 100644 index 0000000..4c33169 --- /dev/null +++ b/favorite_books/web/index.html @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + favorite_books + + + + + + + + + + diff --git a/favorite_books/web/manifest.json b/favorite_books/web/manifest.json new file mode 100644 index 0000000..b062eb4 --- /dev/null +++ b/favorite_books/web/manifest.json @@ -0,0 +1,35 @@ +{ + "name": "favorite_books", + "short_name": "favorite_books", + "start_url": ".", + "display": "standalone", + "background_color": "#0175C2", + "theme_color": "#0175C2", + "description": "A new Flutter project.", + "orientation": "portrait-primary", + "prefer_related_applications": false, + "icons": [ + { + "src": "icons/Icon-192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "icons/Icon-512.png", + "sizes": "512x512", + "type": "image/png" + }, + { + "src": "icons/Icon-maskable-192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "maskable" + }, + { + "src": "icons/Icon-maskable-512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "maskable" + } + ] +} diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..7e0690a --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,23 @@ +name: hivedb_samples +description: A Flutter project for the Hive DB Samples + +environment: + sdk: '>=2.12.0' + +dependencies: + backup_restore_books: + path: ./backup_restore_books + contacts: + path: ./contacts + counter: + path: ./counter + favorite_books: + path: ./favorite_books + sketchpad: + path: ./sketchpad + todo: + path: ./todo + + + +# Your other project-level settings... diff --git a/sketchpad/lib/clear_button.dart b/sketchpad/lib/clear_button.dart index 1d4e1ae..c84b444 100644 --- a/sketchpad/lib/clear_button.dart +++ b/sketchpad/lib/clear_button.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:hive/hive.dart'; import 'package:hive_flutter/hive_flutter.dart'; class ClearButton extends StatelessWidget { diff --git a/sketchpad/lib/colored_path.dart b/sketchpad/lib/colored_path.dart index b34cad7..5791cca 100644 --- a/sketchpad/lib/colored_path.dart +++ b/sketchpad/lib/colored_path.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; class ColoredPath { static const colors = [ @@ -10,10 +9,10 @@ class ColoredPath { Colors.amber, ]; - static List _paints; + static List _paints = []; Paint get paint { - if (_paints == null) { + if (_paints.isEmpty) { _paints = []; for (var color in colors) { _paints.add( diff --git a/sketchpad/lib/drawing_screen.dart b/sketchpad/lib/drawing_screen.dart index 724b006..e87a8fa 100644 --- a/sketchpad/lib/drawing_screen.dart +++ b/sketchpad/lib/drawing_screen.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:hive/hive.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'clear_button.dart'; diff --git a/sketchpad/lib/undo_button.dart b/sketchpad/lib/undo_button.dart index 48685b5..d0c0102 100644 --- a/sketchpad/lib/undo_button.dart +++ b/sketchpad/lib/undo_button.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:hive/hive.dart'; import 'package:hive_flutter/hive_flutter.dart'; class UndoButton extends StatelessWidget { diff --git a/sketchpad/pubspec.yaml b/sketchpad/pubspec.yaml index 9df0753..1da4ecf 100644 --- a/sketchpad/pubspec.yaml +++ b/sketchpad/pubspec.yaml @@ -6,7 +6,7 @@ publish_to: "none" version: 1.0.0 environment: - sdk: ">=2.6.0 <3.0.0" + sdk: '>=2.12.0' dependencies: flutter: @@ -16,6 +16,9 @@ dependencies: hive_flutter: any path_provider: any +dev_dependencies: + flutter_lints: ^2.0.3 + flutter: uses-material-design: true diff --git a/todo/ios/Podfile b/todo/ios/Podfile new file mode 100644 index 0000000..ec43b51 --- /dev/null +++ b/todo/ios/Podfile @@ -0,0 +1,41 @@ +# 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 + 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 diff --git a/todo/lib/main.dart b/todo/lib/main.dart index ed6ec87..da1341c 100644 --- a/todo/lib/main.dart +++ b/todo/lib/main.dart @@ -1,6 +1,5 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:hive/hive.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:todo/new_todo_dialog.dart'; import 'package:todo/todo.dart'; @@ -84,7 +83,7 @@ class TodoMainScreen extends StatelessWidget { ); } - Widget _buildWithBox(BuildContext context, Box settings, Widget child) { + Widget _buildWithBox(BuildContext context, Box settings, Widget? child) { var reversed = settings.get('reversed', defaultValue: true) as bool; return Column( crossAxisAlignment: CrossAxisAlignment.center, diff --git a/todo/lib/new_todo_dialog.dart b/todo/lib/new_todo_dialog.dart index a25197d..6aa9c32 100644 --- a/todo/lib/new_todo_dialog.dart +++ b/todo/lib/new_todo_dialog.dart @@ -35,13 +35,13 @@ class _NewTodoDialogState extends State { ], ), actions: [ - FlatButton( + TextButton( child: Text('Cancel'), onPressed: () { Navigator.of(context).pop(); }, ), - FlatButton( + TextButton( child: Text('Add'), onPressed: () { if (controller.text.isNotEmpty) { diff --git a/todo/lib/todo.dart b/todo/lib/todo.dart index 31e0758..00bfc0a 100644 --- a/todo/lib/todo.dart +++ b/todo/lib/todo.dart @@ -5,10 +5,10 @@ part 'todo.g.dart'; @HiveType(typeId: 0) class Todo extends HiveObject { @HiveField(0) - String name; + late String name; @HiveField(1) - DateTime created; + late DateTime created; @HiveField(2) bool done = false; diff --git a/todo/pubspec.yaml b/todo/pubspec.yaml index b36e3b8..b361e90 100644 --- a/todo/pubspec.yaml +++ b/todo/pubspec.yaml @@ -3,7 +3,7 @@ version: 1.0.0 description: This is a todo sample app for the Hive package. environment: - sdk: ">=2.6.0 <3.0.0" + sdk: '>=2.12.0' dependencies: flutter: @@ -13,8 +13,9 @@ dependencies: hive_flutter: any dev_dependencies: - build_runner: ^2.1.0 + build_runner: ^2.4.6 hive_generator: any + flutter_lints: ^2.0.3 flutter: uses-material-design: true