From 5f99c4f0f9d6d64da5bc6cc332c1e514799ed01a Mon Sep 17 00:00:00 2001 From: Rexios Date: Mon, 5 Aug 2024 22:13:23 -0400 Subject: [PATCH] Working on the example --- .../example/ios/Flutter/Debug.xcconfig | 1 + .../example/ios/Flutter/Release.xcconfig | 1 + hive_flutter/example/ios/Podfile | 44 ++++++ hive_flutter/example/lib/main.dart | 128 ++++-------------- .../macos/Flutter/Flutter-Debug.xcconfig | 1 + .../macos/Flutter/Flutter-Release.xcconfig | 1 + hive_flutter/example/macos/Podfile | 43 ++++++ hive_flutter/example/pubspec.yaml | 5 + 8 files changed, 122 insertions(+), 102 deletions(-) create mode 100644 hive_flutter/example/ios/Podfile create mode 100644 hive_flutter/example/macos/Podfile diff --git a/hive_flutter/example/ios/Flutter/Debug.xcconfig b/hive_flutter/example/ios/Flutter/Debug.xcconfig index 592ceee8..ec97fc6f 100644 --- a/hive_flutter/example/ios/Flutter/Debug.xcconfig +++ b/hive_flutter/example/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/hive_flutter/example/ios/Flutter/Release.xcconfig b/hive_flutter/example/ios/Flutter/Release.xcconfig index 592ceee8..c4855bfe 100644 --- a/hive_flutter/example/ios/Flutter/Release.xcconfig +++ b/hive_flutter/example/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/hive_flutter/example/ios/Podfile b/hive_flutter/example/ios/Podfile new file mode 100644 index 00000000..d97f17e2 --- /dev/null +++ b/hive_flutter/example/ios/Podfile @@ -0,0 +1,44 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '12.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/hive_flutter/example/lib/main.dart b/hive_flutter/example/lib/main.dart index 8e940891..260c6b77 100644 --- a/hive_flutter/example/lib/main.dart +++ b/hive_flutter/example/lib/main.dart @@ -1,125 +1,49 @@ import 'package:flutter/material.dart'; +import 'package:hive_ce_flutter/hive_flutter.dart'; -void main() { - runApp(const MyApp()); -} - -class MyApp extends StatelessWidget { - const MyApp({super.key}); +const counterBox = 'counter'; - // This widget is the root of your application. - @override - Widget build(BuildContext context) { - return MaterialApp( - title: 'Flutter Demo', - theme: ThemeData( - // This is the theme of your application. - // - // TRY THIS: Try running your application with "flutter run". You'll see - // the application has a purple toolbar. Then, without quitting the app, - // try changing the seedColor in the colorScheme below to Colors.green - // and then invoke "hot reload" (save your changes or press the "hot - // reload" button in a Flutter-supported IDE, or press "r" if you used - // the command line to start the app). - // - // Notice that the counter didn't reset back to zero; the application - // state is not lost during the reload. To reset the state, use hot - // restart instead. - // - // This works for code too, not just values: Most code changes can be - // tested with just a hot reload. - colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), - useMaterial3: true, - ), - home: const MyHomePage(title: 'Flutter Demo Home Page'), - ); +void main() async { + WidgetsFlutterBinding.ensureInitialized(); + await Hive.initFlutter(); + final box = await Hive.openBox(counterBox); + if (box.isEmpty) { + await box.add(0); } + runApp(const MaterialApp(home: HiveCounterApp())); } -class MyHomePage extends StatefulWidget { - const MyHomePage({super.key, required this.title}); - - // This widget is the home page of your application. It is stateful, meaning - // that it has a State object (defined below) that contains fields that affect - // how it looks. - - // This class is the configuration for the state. It holds the values (in this - // case the title) provided by the parent (in this case the App widget) and - // used by the build method of the State. Fields in a Widget subclass are - // always marked "final". - - final String title; - - @override - State createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - int _counter = 0; - - void _incrementCounter() { - setState(() { - // This call to setState tells the Flutter framework that something has - // changed in this State, which causes it to rerun the build method below - // so that the display can reflect the updated values. If we changed - // _counter without calling setState(), then the build method would not be - // called again, and so nothing would appear to happen. - _counter++; - }); - } +class HiveCounterApp extends StatelessWidget { + const HiveCounterApp({super.key}); @override Widget build(BuildContext context) { - // This method is rerun every time setState is called, for instance as done - // by the _incrementCounter method above. - // - // The Flutter framework has been optimized to make rerunning build methods - // fast, so that you can just rebuild anything that needs updating rather - // than having to individually change instances of widgets. + final box = Hive.box(counterBox); + return Scaffold( - appBar: AppBar( - // TRY THIS: Try changing the color here to a specific color (to - // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar - // change color while the other colors stay the same. - backgroundColor: Theme.of(context).colorScheme.inversePrimary, - // Here we take the value from the MyHomePage object that was created by - // the App.build method, and use it to set our appbar title. - title: Text(widget.title), - ), + appBar: AppBar(title: const Text('Hive CE Example')), body: Center( - // Center is a layout widget. It takes a single child and positions it - // in the middle of the parent. child: Column( - // Column is also a layout widget. It takes a list of children and - // arranges them vertically. By default, it sizes itself to fit its - // children horizontally, and tries to be as tall as its parent. - // - // Column has various properties to control how it sizes itself and - // how it positions its children. Here we use mainAxisAlignment to - // center the children vertically; the main axis here is the vertical - // axis because Columns are vertical (the cross axis would be - // horizontal). - // - // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint" - // action in the IDE, or press "p" in the console), to see the - // wireframe for each widget. mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text( - 'You have pushed the button this many times:', - ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headlineMedium, + children: [ + const Text('You have pushed the button this many times:'), + ValueListenableBuilder( + valueListenable: box.listenable(), + builder: (context, box, widget) { + return Text( + box.getAt(0).toString(), + style: Theme.of(context).textTheme.headlineMedium, + ); + }, ), ], ), ), floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, + onPressed: () => box.putAt(0, box.getAt(0) + 1), tooltip: 'Increment', child: const Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. + ), ); } } diff --git a/hive_flutter/example/macos/Flutter/Flutter-Debug.xcconfig b/hive_flutter/example/macos/Flutter/Flutter-Debug.xcconfig index c2efd0b6..4b81f9b2 100644 --- a/hive_flutter/example/macos/Flutter/Flutter-Debug.xcconfig +++ b/hive_flutter/example/macos/Flutter/Flutter-Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "ephemeral/Flutter-Generated.xcconfig" diff --git a/hive_flutter/example/macos/Flutter/Flutter-Release.xcconfig b/hive_flutter/example/macos/Flutter/Flutter-Release.xcconfig index c2efd0b6..5caa9d15 100644 --- a/hive_flutter/example/macos/Flutter/Flutter-Release.xcconfig +++ b/hive_flutter/example/macos/Flutter/Flutter-Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "ephemeral/Flutter-Generated.xcconfig" diff --git a/hive_flutter/example/macos/Podfile b/hive_flutter/example/macos/Podfile new file mode 100644 index 00000000..c795730d --- /dev/null +++ b/hive_flutter/example/macos/Podfile @@ -0,0 +1,43 @@ +platform :osx, '10.14' + +# 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', 'ephemeral', '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 Flutter-Generated.xcconfig, then run \"flutter pub get\"" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_macos_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_macos_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_macos_build_settings(target) + end +end diff --git a/hive_flutter/example/pubspec.yaml b/hive_flutter/example/pubspec.yaml index 8dc045f6..3a2d5eea 100644 --- a/hive_flutter/example/pubspec.yaml +++ b/hive_flutter/example/pubspec.yaml @@ -8,9 +8,14 @@ environment: dependencies: flutter: sdk: flutter + hive_ce_flutter: + path: ../../hive_flutter dev_dependencies: rexios_lints: ^7.0.0 + build_runner: ^2.4.0 + hive_ce_generator: + path: ../../hive_generator flutter: uses-material-design: true