Skip to content
Merged
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ When utilizing the `nitric new` command to initiate a new project, the available

### Dart

| Name | Description | Features |
| ---------------------------------- | ---------------- | -------- |
| [dart-starter](./v1/dart-starter/) | REST API Starter | APIs |
| Name | Description | Features |
| ---------------------------------- | ----------------------------------------------- | ---------------------- |
| [dart-starter](./v1/dart-starter/) | REST API Starter | APIs |
| [flutter](./v1/flutter/) | Basic Flutter Application with a Nitric backend | APIs, Key Value Stores |

### Go

Expand Down
43 changes: 43 additions & 0 deletions v1/flutter/.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
45 changes: 45 additions & 0 deletions v1/flutter/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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: "b0850beeb25f6d5b10426284f506557f66181b36"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: b0850beeb25f6d5b10426284f506557f66181b36
base_revision: b0850beeb25f6d5b10426284f506557f66181b36
- platform: android
create_revision: b0850beeb25f6d5b10426284f506557f66181b36
base_revision: b0850beeb25f6d5b10426284f506557f66181b36
- platform: ios
create_revision: b0850beeb25f6d5b10426284f506557f66181b36
base_revision: b0850beeb25f6d5b10426284f506557f66181b36
- platform: linux
create_revision: b0850beeb25f6d5b10426284f506557f66181b36
base_revision: b0850beeb25f6d5b10426284f506557f66181b36
- platform: macos
create_revision: b0850beeb25f6d5b10426284f506557f66181b36
base_revision: b0850beeb25f6d5b10426284f506557f66181b36
- platform: web
create_revision: b0850beeb25f6d5b10426284f506557f66181b36
base_revision: b0850beeb25f6d5b10426284f506557f66181b36
- platform: windows
create_revision: b0850beeb25f6d5b10426284f506557f66181b36
base_revision: b0850beeb25f6d5b10426284f506557f66181b36

# 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'
64 changes: 64 additions & 0 deletions v1/flutter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<p align="center">
<a href="https://nitric.io">
<img src="https://raw.githubusercontent.com/nitrictech/nitric/main/docs/assets/nitric-logo.svg" width="120" alt="Nitric Logo"/>
</a>
</p>

<p align="center">
A fast & fun way to build portable cloud-native applications
</p>

<p align="center">
<img alt="GitHub release (latest SemVer)" src="https://img.shields.io/github/v/release/nitrictech/nitric?sort=semver">
<a href="https://twitter.com/nitric_io">
<img alt="Twitter Follow" src="https://img.shields.io/twitter/follow/nitric_io?label=Follow&style=social">
</a>
<a href="https://nitric.io/chat"><img alt="Discord" src="https://img.shields.io/discord/955259353043173427?label=discord"></a>
</p>

## Project Description

A basic Flutter application that uses Nitric as the backend service for the API and key value collections.

## Running this project

To run this project you'll need the [Nitric CLI](https://nitric.io/docs/installation) installed, then you can use the CLI commands to run, build or deploy the project.

You'll also want to make sure the project's required dependencies have been installed.

```bash
# install dependencies
dart pub get

# run locally
nitric start
```

## About Nitric

[Nitric](https://nitric.io) is a framework for rapid development of cloud-native and serverless applications. Define your apps in terms of the resources they need, then write the code for serverless function based APIs, event subscribers and scheduled jobs.

Apps built with Nitric can be deployed to AWS, Azure or Google Cloud all from the same code base so you can focus on your products, not your cloud provider.

Nitric makes it easy to:

- Create smart serverless functions and APIs
- Build reliable distributed apps that use events and/or queues
- Securely store and retrieve secrets
- Read and write files from buckets

## Documentation

The full documentation is available at [nitric.io/docs](https://nitric.io/docs).

We're completely open-source and encourage [code contributions](https://nitric.io/docs/contributions).

## Get in touch

- Jump into our [Discord server](https://nitric.io/chat)

- Ask questions in [GitHub discussions](https://github.com/nitrictech/nitric/discussions)

- Find us on [Twitter](https://twitter.com/nitric_io)

- Send us an [email](mailto:[email protected])
28 changes: 28 additions & 0 deletions v1/flutter/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
40 changes: 40 additions & 0 deletions v1/flutter/docker/flutter.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM dart:stable AS build

# The Nitric CLI will provide the HANDLER arg with the location of our service
ARG HANDLER
WORKDIR /app

ENV DEBIAN_FRONTEND=noninteractive

# download Flutter SDK from Flutter Github repo
RUN git clone https://github.com/flutter/flutter.git /usr/local/flutter

ENV DEBIAN_FRONTEND=dialog

# Set flutter environment path
ENV PATH="/usr/local/flutter/bin:/usr/local/flutter/bin/cache/dart-sdk/bin:${PATH}"

# Run flutter doctor
RUN flutter doctor

# Resolve app dependencies.
COPY pubspec.* ./
RUN flutter pub get

# Ensure the ./bin folder exists
RUN mkdir -p ./bin

# Copy app source code and AOT compile it.
COPY . .
# Ensure packages are still up-to-date if anything has changed
RUN flutter pub get --offline
# Compile the dart service into an exe
RUN dart compile exe ./${HANDLER} -o bin/main

# Start from scratch and copy in the necessary runtime files
FROM alpine

COPY --from=build /runtime/ /
COPY --from=build /app/bin/main /app/bin/

ENTRYPOINT ["/app/bin/main"]
13 changes: 13 additions & 0 deletions v1/flutter/docker/flutter.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
build
test
.nitric
.idea
.dart_tool
.git
docker
android
ios
linux
macos
web
windows
23 changes: 23 additions & 0 deletions v1/flutter/lib/cors.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:nitric_sdk/nitric.dart';

/// Handle Preflight Options requests by returning status 200 to the requests
Future<HttpContext> optionsHandler(HttpContext ctx) async {
ctx.res.headers["Content-Type"] = ["text/html; charset=ascii"];
ctx.res.body = "OK";

return ctx.next();
}

/// Add CORS headers to responses
Future<HttpContext> addCors(HttpContext ctx) async {
ctx.res.headers["Access-Control-Allow-Origin"] = ["*"];
ctx.res.headers["Access-Control-Allow-Headers"] = [
"Origin, X-Requested-With, Content-Type, Accept, Authorization",
];
ctx.res.headers["Access-Control-Allow-Methods"] = [
"GET, PUT, POST, PATCH, OPTIONS, DELETE",
];
ctx.res.headers["Access-Control-Max-Age"] = ["7200"];

return ctx.next();
}
13 changes: 13 additions & 0 deletions v1/flutter/lib/favorite.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Favorite {
/// The name of the favorite
String name;

Favorite(this.name);

/// Convert a json decodable map to a Favorite object
Favorite.fromJson(Map<String, dynamic> json) : name = json['name'];

/// Convert a Favorite object to a json encodable
static Map<String, dynamic> toJson(Favorite favorite) =>
{'name': favorite.name};
}
28 changes: 28 additions & 0 deletions v1/flutter/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:word_generator/pages/home.dart';
import 'package:word_generator/providers/favorites.dart';
import 'package:word_generator/providers/word.dart';

void main() => runApp(Application());

class Application extends StatelessWidget {
const Application({super.key});
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => FavoritesProvider()),
ChangeNotifierProvider(create: (context) => WordProvider()),
],
child: MaterialApp(
title: 'Word Generator App',
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
),
home: HomePage(), // <-- Change here
),
);
}
}
40 changes: 40 additions & 0 deletions v1/flutter/lib/pages/favorites.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:word_generator/providers/favorites.dart';

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

@override
Widget build(BuildContext context) {
var favorites = context.watch<FavoritesProvider>();

// If the favorites list is still loading then show a spinning circle.
if (favorites.isLoading) {
return const Center(
child: SizedBox(
width: 40,
height: 40,
child: CircularProgressIndicator(color: Colors.blue),
));
}

// Otherwise return a list of all the favorites
return ListView(
children: [
Padding(
padding: const EdgeInsets.all(20),
// Display how many favorites there are
child: Text('You have '
'${favorites.favorites.length} favorites:'),
),
// Create a list tile for every favorite in the list of favorites
for (var favorite in favorites.favorites)
ListTile(
leading: Icon(Icons.favorite), // <- A heart icon
title: Text(favorite.name),
),
],
);
}
}
Loading