Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NULL SAFETY SUPPORT WITH FLUTTER 3.0.0 #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
89 changes: 45 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,59 +17,60 @@ Check out [blog post](https://fidev.io/thanos) describing the package on [Fidev]
import 'package:snappable/snappable.dart';
```

### Wrap any widget in Snappable
```dart
@override
Widget build(BuildContext context) {
return Snappable(
child: Text('This will be snapped'),
);
}
```
#### Snap with a Key
```dart

class MyWidget extends StatelessWidget {
final key = GlobalKey<SnappableState>();
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Snappable(
key: key,
child: Text('This will be snapped'),
);
}

void snap() {
key.currentState.snap();
}
MyHomePageState createState() => MyHomePageState();
}
```
Undo by `currentState.reset()`.
#### or snap by tap
```dart

class MyWidget extends StatelessWidget {
class MyHomePageState extends State<MyHomePage> {
final _snappableKey = GlobalKey<SnappableState>();

@override
Widget build(BuildContext context) {
return Snappable(
snapOntap: true,
child: Text('This will be snapped'),
return Scaffold(
appBar: AppBar(
title: const Text('Snap'),
),
body: Column(
children: <Widget>[
Snappable(
key: _snappableKey,
snapOnTap: true,
onSnapped: () => print("Snapped!"),
child: Card(
child: Container(
height: 300,
width: double.infinity,
color: Colors.deepPurple,
alignment: Alignment.center,
child: Text(
'This will be sanpped',
style: Theme.of(context).textTheme.headline6!.copyWith(
color: Colors.white,
),
),
),
),
),
RaisedButton(
child: const Text('Snap / Reverse'),
onPressed: () {
SnappableState state = _snappableKey.currentState!;
if (state.isGone) {
state.reset();
} else {
state.snap();
}
},
)
],
),
);
}
}
```
Undo by tapping again.

### Callback for when the snap ends
```dart

class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Snappable(
onSnapped: () => print("Snapped!"),
child: Text('This will be snapped'),
);
}
}
```
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
47 changes: 47 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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
.packages
.pub-cache/
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart

# 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 example/.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.

version:
revision: 676cefaaff197f27424942307668886253e1ec35
channel: stable

project_type: app

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

# 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'
55 changes: 9 additions & 46 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,16 @@
# snappable
# example

Check out [blog post](https://fidev.io/thanos) describing the package on [Fidev](https://fidev.io).
A new Flutter project.

## Getting Started

### Import it
```dart
import 'package:snappable/snappable.dart';
```
This project is a starting point for a Flutter application.

### Wrap any widget in Snappable
```dart
@override
Widget build(BuildContext context) {
return Snappable(
child: Text('This whill be snapped'),
);
}
```
#### Snap with a Key
```dart
A few resources to get you started if this is your first Flutter project:

class MyWidget extends StatelessWidget {
final key = GlobalKey<SnappableState>();
@override
Widget build(BuildContext context) {
return Snappable(
key: key,
child: Text('This whill be snapped'),
);
}

void snap() {
key.currentState.snap();
}
}
```
Undo by `currentState.reset()`.
#### or snap by tap
```dart
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)

class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Snappable(
snapOntap: true,
child: Text('This whill be snapped'),
);
}
}
```
Undo by tapping again.
For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
29 changes: 29 additions & 0 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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-lang.github.io/linter/lints/index.html.
#
# 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
13 changes: 13 additions & 0 deletions example/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
gradle-wrapper.jar
/.gradle
/captures/
/gradlew
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java

# Remember to never publicly share your keystore.
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
key.properties
**/*.keystore
**/*.jks
28 changes: 19 additions & 9 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,35 @@ if (flutterVersionName == null) {
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion

lintOptions {
disable 'InvalidPackage'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.example"
minSdkVersion 16
targetSdkVersion 28
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
Expand All @@ -55,7 +67,5 @@ flutter {
}

dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
3 changes: 2 additions & 1 deletion example/android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example">
<!-- Flutter needs it to communicate with the running application
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
Expand Down
Loading