Skip to content

Commit

Permalink
Add full example app
Browse files Browse the repository at this point in the history
  • Loading branch information
tp committed Oct 29, 2024
1 parent 79e475e commit 7dd8184
Show file tree
Hide file tree
Showing 52 changed files with 2,681 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "IndexedEntityStore Example",
"cwd": "example",
"request": "launch",
"type": "dart"
}
]
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.4.2

* Add full example app
* Implement `DisposableValueListenable` for `QueryResult`

## 1.4.1

* Add `deleteAll` method
Expand Down
43 changes: 43 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.pub-cache/
.pub/
/build/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
30 changes: 30 additions & 0 deletions example/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "2663184aa79047d0a33a14a3b607954f8fdd8730"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: macos
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730

# 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'
6 changes: 5 additions & 1 deletion example/example.md → example/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
### Example

See the detailed app for a full-blown example. Or look below for a simple introduction.

#### Simple example

Let's see how this would look for a simple TODO list application.

```dart
Expand Down Expand Up @@ -60,7 +64,7 @@ final todoConnector = IndexedEntityConnector<Todo, int /* key type */, String /*
index((t) => t.done, as: 'done');
},
serialize: (t) => jsonEncode(t.toJSON()),
deserialize: (s) => _FooEntity.fromJSON(
deserialize: (s) => Todo.fromJSON(
jsonDecode(s) as Map<String, dynamic>,
),
);
Expand Down
28 changes: 28 additions & 0 deletions example/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
72 changes: 72 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:indexed_entity_store_example/src/examples/async_value_group_and_detail.dart';
import 'package:indexed_entity_store_example/src/examples/simple_synchronous.dart';
import 'package:path_provider/path_provider.dart';

late final Directory applicationCacheDirectory;

void main() async {
// Normally this setup would of course be done after the initial frame / loading screen is rendered
WidgetsFlutterBinding.ensureInitialized();
applicationCacheDirectory = await getApplicationCacheDirectory();

runApp(const IndexedEntityStoreExampleApp());
}

class IndexedEntityStoreExampleApp extends StatelessWidget {
const IndexedEntityStoreExampleApp({super.key});

@override
Widget build(BuildContext context) {
return const CupertinoApp(
home: ExampleSelector(),
);
}
}

class ExampleSelector extends StatefulWidget {
const ExampleSelector({
super.key,
});

@override
State<ExampleSelector> createState() => _ExampleSelectorState();
}

class _ExampleSelectorState extends State<ExampleSelector> {
Widget? _example;

static Map<String, Widget> examples = {
'Simple synchronous data repository': const SimpleSynchronousExample(),
'AsyncValue-based product list & detail view':
const AsyncValueGroupDetailExample(),
};

@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('Examples'),
),
child: SafeArea(
child: _example ??
ListView(
children: [
for (final MapEntry(key: name, value: widget)
in examples.entries)
CupertinoListTile(
onTap: () {
setState(() {
_example = widget;
});
},
title: Text(name),
),
],
),
),
);
}
}
Loading

0 comments on commit 7dd8184

Please sign in to comment.