Skip to content

Commit

Permalink
Added support for FocusScope class
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Massango committed Apr 23, 2020
1 parent 4822f6a commit 7baf710
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 23 deletions.
41 changes: 29 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@

## [1.1.0] - 23/04/2020.

* Added support for:

* `context.focusScope.hasFocus`
* `context.focusScope.isFirstFocus`
* `context.focusScope.canRequestFocus`
* `context.focusScope.hasPrimaryFocus`


* `context.focusScope.unfocus()`
* `context.focusScope.nextFocus()`
* `context.focusScope.requestFocus()`
* `context.focusScope.previousFocus()`
* `context.focusScope.setFirstFocus()`
* `context.focusScope.consumeKeyboardToken()`

## [1.0.0] - 21/04/2020.

Added support for:
Expand All @@ -17,28 +34,28 @@ Added support for:

Added support for:

* context.form.validate()
* context.form.reset()
* context.form.save()
* `context.form.validate()`
* `context.form.reset()`
* `context.form.save()`

## [0.0.3] - 03/04/2020.

Added support for:

* context.isLandscape
* context.isPortrait
* context.mediaQueryViewInsets
* context.mediaQueryViewPadding
* `context.isLandscape`
* `context.isPortrait`
* `context.mediaQueryViewInsets`
* `context.mediaQueryViewPadding`

## [0.0.2] - 03/04/2020.

* Fixed README.md format issue

## [0.0.1] - 02/04/2020.

Added support for:
Added support for the following classes:

* MediaQuery
* Theme
* Navigator
* Scaffold
* `MediaQuery`
* `Theme`
* `Navigator`
* `Scaffold`
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,25 @@ Note: those must be called in the context of a `Scaffold` widget otherwise you m

#### From `FocusScope.of(context)` class.

* `context.focusScope.hasFocus`
* `context.focusScope.isFirstFocus`
* `context.focusScope.canRequestFocus`
* `context.focusScope.hasPrimaryFocus`

* `context.focusScope.unfocus()`
* `context.focusScope.nextFocus()`
* `context.focusScope.requestFocus()`
* `context.focusScope.previousFocus()`
* `context.focusScope.setFirstFocus()`
* `context.focusScope.consumeKeyboardToken()`

# Install

Add it in your `pubspec.yaml`:

````yaml
dependencies:
build_context: ^1.0.0
build_context: ^1.1.0
````

Import it where you want to use it e.g, in your widget's file.
Expand All @@ -87,7 +97,7 @@ Import it where you want to use it e.g, in your widget's file.
import "package:build_context/build_context.dart";
```

Here is an usage example:
Here is a usage example:

```dart
import 'package:flutter/material.dart';
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.0"
version: "1.1.0"
charcode:
dependency: transitive
description:
Expand Down
30 changes: 23 additions & 7 deletions lib/src/build_context_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,32 @@ extension FormExt on BuildContext {
}

class _FocusScope {
_FocusScope(this._context);
const _FocusScope(this._context);

final BuildContext _context;

FocusScopeNode _node() => FocusScope.of(_context);

void unfocus() {
FocusScopeNode currentFocus = FocusScope.of(_context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
}
bool get hasFocus => _node().hasFocus;

bool get isFirstFocus => _node().isFirstFocus;

bool get hasPrimaryFocus => _node().hasPrimaryFocus;

bool get canRequestFocus => _node().canRequestFocus;

void nextFocus() => _node().nextFocus();

void requestFocus([FocusNode node]) => _node().requestFocus(node);

void previousFocus() => _node().previousFocus();

void unfocus([bool focusPrevious = false]) =>
_node().unfocus(focusPrevious: focusPrevious);

void setFirstFocus(FocusScopeNode scope) => _node().setFirstFocus(scope);

bool consumeKeyboardToken() => _node().consumeKeyboardToken();
}

extension FocusScopeExt on BuildContext {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: build_context
description: A package that simplifies the access most of used properties/fuctions right in the BuildContext.
version: 1.0.0
version: 1.1.0
homepage: https://github.com/pedromassango/build_context

environment:
Expand Down

0 comments on commit 7baf710

Please sign in to comment.