Compare commits
No commits in common. "rust_rewrite" and "main" have entirely different histories.
rust_rewri
...
main
447 changed files with 59859 additions and 50785 deletions
11
adaptive_number/LICENSE
Normal file
11
adaptive_number/LICENSE
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
Copyright 2021 Philipp Sessler
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
6
adaptive_number/lib/adaptive_number.dart
Normal file
6
adaptive_number/lib/adaptive_number.dart
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
/// Support for doing something awesome.
|
||||
///
|
||||
/// More dartdocs go here.
|
||||
library adaptive_number;
|
||||
|
||||
export 'src/number.dart';
|
||||
120
adaptive_number/lib/src/int.dart
Normal file
120
adaptive_number/lib/src/int.dart
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
import 'package:adaptive_number/src/number.dart';
|
||||
|
||||
class NumberInt implements Number {
|
||||
final int _value;
|
||||
|
||||
NumberInt(this._value);
|
||||
|
||||
@override
|
||||
NumberInt operator +(Number value) {
|
||||
return NumberInt(_value + (value.val as int));
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt operator -(Number value) {
|
||||
return NumberInt(_value - (value.val as int));
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt operator -() {
|
||||
return NumberInt(-(val));
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt operator *(Number value) {
|
||||
return NumberInt(_value * (value.val as int));
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt operator &(Number value) {
|
||||
return NumberInt(_value & (value.val as int));
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt operator >>(int value) {
|
||||
return NumberInt(_value >> value);
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt operator <<(int value) {
|
||||
return NumberInt(_value << value);
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt operator ^(Number value) {
|
||||
return NumberInt(_value ^ (value.val as int));
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt operator |(Number value) {
|
||||
return NumberInt(_value | (value.val as int));
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator <(Number value) {
|
||||
return (intValue < value.intValue);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator <=(Number value) {
|
||||
return (intValue <= value.intValue);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator >(Number value) {
|
||||
return (intValue > value.intValue);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator >=(Number value) {
|
||||
return (intValue >= value.intValue);
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt operator %(Number value) {
|
||||
return NumberInt(_value % (value.val as int));
|
||||
}
|
||||
|
||||
@override
|
||||
Number operator ~/(Number value) {
|
||||
return NumberInt(_value ~/ (value.val as int));
|
||||
}
|
||||
|
||||
@override
|
||||
int get val => _value;
|
||||
|
||||
@override
|
||||
int get intValue => _value;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is NumberInt &&
|
||||
runtimeType == other.runtimeType &&
|
||||
_value == other._value;
|
||||
|
||||
@override
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return _value.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
String toRadixString(int radix) {
|
||||
return _value.toRadixString(radix);
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt abs() {
|
||||
return NumberInt(_value.abs());
|
||||
}
|
||||
|
||||
@override
|
||||
int compareTo(Number other) {
|
||||
return _value.compareTo(other.intValue);
|
||||
}
|
||||
}
|
||||
|
||||
Number createNumber(int val) => NumberInt(val);
|
||||
121
adaptive_number/lib/src/int64.dart
Normal file
121
adaptive_number/lib/src/int64.dart
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
import 'package:adaptive_number/src/number.dart';
|
||||
import 'package:fixnum/fixnum.dart';
|
||||
|
||||
class NumberInt64 implements Number {
|
||||
final Int64 _value;
|
||||
|
||||
NumberInt64(this._value);
|
||||
|
||||
@override
|
||||
NumberInt64 operator +(Number value) {
|
||||
return NumberInt64(_value + (value.val as Int64));
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt64 operator -(Number value) {
|
||||
return NumberInt64(_value - (value.val as Int64));
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt64 operator -() {
|
||||
return NumberInt64(-(val));
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt64 operator *(Number value) {
|
||||
return NumberInt64(_value * (value.val as Int64));
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt64 operator &(Number value) {
|
||||
return NumberInt64(_value & (value.val as Int64));
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt64 operator >>(int value) {
|
||||
return NumberInt64(_value >> value);
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt64 operator <<(int value) {
|
||||
return NumberInt64(_value << value);
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt64 operator ^(Number value) {
|
||||
return NumberInt64(_value ^ (value.val as Int64));
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt64 operator |(Number value) {
|
||||
return NumberInt64(_value | (value.val as Int64));
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator <(Number value) {
|
||||
return (intValue < value.intValue);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator <=(Number value) {
|
||||
return (intValue <= value.intValue);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator >(Number value) {
|
||||
return (intValue > value.intValue);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator >=(Number value) {
|
||||
return (intValue >= value.intValue);
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt64 operator %(Number value) {
|
||||
return NumberInt64(_value % (value.val as Int64));
|
||||
}
|
||||
|
||||
@override
|
||||
Number operator ~/(Number value) {
|
||||
return NumberInt64(_value ~/ (value.val as Int64));
|
||||
}
|
||||
|
||||
@override
|
||||
Int64 get val => _value;
|
||||
|
||||
@override
|
||||
int get intValue => _value.toInt();
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is NumberInt64 &&
|
||||
runtimeType == other.runtimeType &&
|
||||
_value == other._value;
|
||||
|
||||
@override
|
||||
int get hashCode => _value.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return _value.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
String toRadixString(int radix) {
|
||||
return _value.toRadixString(radix);
|
||||
}
|
||||
|
||||
@override
|
||||
NumberInt64 abs() {
|
||||
return NumberInt64(_value.abs());
|
||||
}
|
||||
|
||||
@override
|
||||
int compareTo(Number value) {
|
||||
return _value.compareTo(value.val as Int64);
|
||||
}
|
||||
}
|
||||
|
||||
Number createNumber(int val) => NumberInt64(Int64(val));
|
||||
78
adaptive_number/lib/src/number.dart
Normal file
78
adaptive_number/lib/src/number.dart
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import 'package:adaptive_number/src/stub.dart'
|
||||
// ignore: uri_does_not_exist
|
||||
if (dart.library.io) 'package:adaptive_number/src/int.dart'
|
||||
// ignore: uri_does_not_exist
|
||||
if (dart.library.html) 'package:adaptive_number/src/int64.dart';
|
||||
|
||||
abstract class Number {
|
||||
static Number zero = Number(0);
|
||||
static Number one = Number(1);
|
||||
static Number two = Number(2);
|
||||
|
||||
factory Number(int val) => createNumber(val);
|
||||
|
||||
dynamic get val;
|
||||
|
||||
/// Returns the value as int (caution: May overflow on JS runtimes)
|
||||
int get intValue;
|
||||
|
||||
@override
|
||||
int get hashCode;
|
||||
|
||||
/// Addition operator.
|
||||
Number operator +(Number value);
|
||||
|
||||
/// Subtraction operator.
|
||||
Number operator -(Number value);
|
||||
|
||||
/// Negate operator.
|
||||
Number operator -();
|
||||
|
||||
/// Multiplication operator.
|
||||
Number operator *(Number value);
|
||||
|
||||
/// Bitwise and operator.
|
||||
Number operator &(Number value);
|
||||
|
||||
/// Right bit-shift operator.
|
||||
Number operator >>(int value);
|
||||
|
||||
/// Left bit-shift operator.
|
||||
Number operator <<(int value);
|
||||
|
||||
/// Bitwise xor operator.
|
||||
Number operator ^(Number value);
|
||||
|
||||
/// Bitwise or operator.
|
||||
Number operator |(Number value);
|
||||
|
||||
/// Relational less than operator.
|
||||
bool operator <(Number value);
|
||||
|
||||
/// Relational less than or equal to operator.
|
||||
bool operator <=(Number value);
|
||||
|
||||
/// Relational greater than operator.
|
||||
bool operator >(Number value);
|
||||
|
||||
/// Relational greater than or equal to operator.
|
||||
bool operator >=(Number value);
|
||||
|
||||
/// Euclidean modulo operator.
|
||||
Number operator %(Number value);
|
||||
|
||||
/// Truncating division operator.
|
||||
Number operator ~/(Number value);
|
||||
|
||||
@override
|
||||
String toString();
|
||||
|
||||
/// Returns a string representing the value of this integer in the given radix.
|
||||
String toRadixString(int radix);
|
||||
|
||||
/// Returns the absolute value of this integer.
|
||||
Number abs();
|
||||
|
||||
// Compares this to `other`
|
||||
int compareTo(Number other);
|
||||
}
|
||||
4
adaptive_number/lib/src/stub.dart
Normal file
4
adaptive_number/lib/src/stub.dart
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import 'package:adaptive_number/src/number.dart';
|
||||
|
||||
Number createNumber(int val) => throw UnsupportedError(
|
||||
'Cannot create a Number without package dart.library.io or dart.library.html being available');
|
||||
17
adaptive_number/pubspec.yaml
Normal file
17
adaptive_number/pubspec.yaml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
name: adaptive_number
|
||||
version: 1.0.0
|
||||
|
||||
description: >-
|
||||
Library providing an adaptive number implementation. On JS runtimes, a 64-bit signed fixed-width integer will be used and
|
||||
for all other platforms the default Dart int data type.
|
||||
homepage: https://github.com/lemoony/adaptive_number_dart
|
||||
|
||||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
|
||||
dependencies:
|
||||
fixnum: ^1.0.0
|
||||
|
||||
dev_dependencies:
|
||||
pedantic: ^1.10.0
|
||||
test: ^1.16.0
|
||||
201
ed25519_edwards/LICENSE
Normal file
201
ed25519_edwards/LICENSE
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
204
ed25519_edwards/lib/ed25519_edwards.dart
Normal file
204
ed25519_edwards/lib/ed25519_edwards.dart
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
/// Package ed25519 implements the Ed25519 signature algorithm. See
|
||||
/// https://ed25519.cr.yp.to/.
|
||||
///
|
||||
/// These functions are also compatible with the “Ed25519” function defined in
|
||||
/// RFC 8032. However, unlike RFC 8032's formulation, this package's private key
|
||||
/// representation includes a public key suffix to make multiple signing
|
||||
/// operations with the same key more efficient. This package refers to the RFC
|
||||
/// 8032 private key as the “seed”.
|
||||
|
||||
library edwards25519;
|
||||
|
||||
import 'dart:typed_data';
|
||||
import 'package:convert/convert.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:ed25519_edwards/src/edwards25519.dart';
|
||||
import 'package:ed25519_edwards/src/util.dart';
|
||||
|
||||
/// PublicKeySize is the size, in bytes, of public keys as used in this package.
|
||||
const PublicKeySize = 32;
|
||||
|
||||
/// PrivateKeySize is the size, in bytes, of private keys as used in this package.
|
||||
const PrivateKeySize = 64;
|
||||
|
||||
/// SignatureSize is the size, in bytes, of signatures generated and verified by this package.
|
||||
const SignatureSize = 64;
|
||||
|
||||
/// SeedSize is the size, in bytes, of private key seeds. These are the private key representations used by RFC 8032.
|
||||
const SeedSize = 32;
|
||||
|
||||
/// PublicKey is the type of Ed25519 public keys.
|
||||
class PublicKey {
|
||||
List<int> bytes;
|
||||
|
||||
PublicKey(this.bytes);
|
||||
}
|
||||
|
||||
/// PrivateKey is the type of Ed25519 private keys.
|
||||
class PrivateKey {
|
||||
List<int> bytes;
|
||||
|
||||
PrivateKey(this.bytes);
|
||||
}
|
||||
|
||||
/// KeyPair is the type of Ed25519 public/private key pair.
|
||||
class KeyPair {
|
||||
final PrivateKey privateKey;
|
||||
|
||||
final PublicKey publicKey;
|
||||
|
||||
KeyPair(this.privateKey, this.publicKey);
|
||||
|
||||
@override
|
||||
int get hashCode => publicKey.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(other) =>
|
||||
other is KeyPair &&
|
||||
publicKey == other.publicKey &&
|
||||
privateKey == other.privateKey;
|
||||
}
|
||||
|
||||
/// public returns the PublicKey corresponding to PrivateKey.
|
||||
PublicKey public(PrivateKey privateKey) {
|
||||
var publicKey = privateKey.bytes.sublist(32, 32 + PublicKeySize);
|
||||
return PublicKey(publicKey);
|
||||
}
|
||||
|
||||
/// Seed returns the private key seed corresponding to priv. It is provided for
|
||||
/// interoperability with RFC 8032. RFC 8032's private keys correspond to seeds
|
||||
/// in this package.
|
||||
Uint8List seed(PrivateKey privateKey) {
|
||||
var seed = privateKey.bytes.sublist(0, SeedSize);
|
||||
return seed as Uint8List;
|
||||
}
|
||||
|
||||
/// GenerateKey generates a public/private key pair using entropy from secure random.
|
||||
KeyPair generateKey() {
|
||||
var seed = Uint8List(32);
|
||||
fillBytesWithSecureRandomNumbers(seed);
|
||||
var privateKey = newKeyFromSeed(seed);
|
||||
var publicKey = privateKey.bytes.sublist(32, PrivateKeySize);
|
||||
return KeyPair(privateKey, PublicKey(publicKey));
|
||||
}
|
||||
|
||||
/// NewKeyFromSeed calculates a private key from a seed. It will throw
|
||||
/// ArgumentError if seed.length is not SeedSize.
|
||||
/// This function is provided for interoperability with RFC 8032.
|
||||
/// RFC 8032's private keys correspond to seeds in this package.
|
||||
PrivateKey newKeyFromSeed(Uint8List seed) {
|
||||
if (seed.length != SeedSize) {
|
||||
throw ArgumentError('ed25519: bad seed length ${seed.length}');
|
||||
}
|
||||
var h = sha512.convert(seed);
|
||||
var digest = h.bytes.sublist(0, 32);
|
||||
digest[0] &= 248;
|
||||
digest[31] &= 127;
|
||||
digest[31] |= 64;
|
||||
|
||||
var A = ExtendedGroupElement();
|
||||
var hBytes = digest.sublist(0);
|
||||
GeScalarMultBase(A, hBytes as Uint8List);
|
||||
var publicKeyBytes = Uint8List(32);
|
||||
A.ToBytes(publicKeyBytes);
|
||||
|
||||
var privateKey = Uint8List(PrivateKeySize);
|
||||
arrayCopy(seed, 0, privateKey, 0, 32);
|
||||
arrayCopy(publicKeyBytes, 0, privateKey, 32, 32);
|
||||
return PrivateKey(privateKey);
|
||||
}
|
||||
|
||||
/// Sign signs the message with privateKey and returns a signature. It will
|
||||
/// throw ArumentError if privateKey.bytes.length is not PrivateKeySize.
|
||||
Uint8List sign(PrivateKey privateKey, Uint8List message) {
|
||||
if (privateKey.bytes.length != PrivateKeySize) {
|
||||
throw ArgumentError(
|
||||
'ed25519: bad privateKey length ${privateKey.bytes.length}');
|
||||
}
|
||||
var h = sha512.convert(privateKey.bytes.sublist(0, 32));
|
||||
var digest1 = h.bytes;
|
||||
var expandedSecretKey = digest1.sublist(0, 32);
|
||||
expandedSecretKey[0] &= 248;
|
||||
expandedSecretKey[31] &= 63;
|
||||
expandedSecretKey[31] |= 64;
|
||||
|
||||
var output = AccumulatorSink<Digest>();
|
||||
var input = sha512.startChunkedConversion(output);
|
||||
input.add(digest1.sublist(32));
|
||||
input.add(message);
|
||||
input.close();
|
||||
var messageDigest = output.events.single.bytes;
|
||||
|
||||
var messageDigestReduced = Uint8List(32);
|
||||
ScReduce(messageDigestReduced, messageDigest as Uint8List);
|
||||
var R = ExtendedGroupElement();
|
||||
GeScalarMultBase(R, messageDigestReduced);
|
||||
|
||||
var encodedR = Uint8List(32);
|
||||
R.ToBytes(encodedR);
|
||||
|
||||
output = AccumulatorSink<Digest>();
|
||||
input = sha512.startChunkedConversion(output);
|
||||
input.add(encodedR);
|
||||
input.add(privateKey.bytes.sublist(32));
|
||||
input.add(message);
|
||||
input.close();
|
||||
var hramDigest = output.events.single.bytes;
|
||||
var hramDigestReduced = Uint8List(32);
|
||||
ScReduce(hramDigestReduced, hramDigest as Uint8List);
|
||||
|
||||
var s = Uint8List(32);
|
||||
ScMulAdd(s, hramDigestReduced, expandedSecretKey as Uint8List,
|
||||
messageDigestReduced);
|
||||
|
||||
var signature = Uint8List(SignatureSize);
|
||||
arrayCopy(encodedR, 0, signature, 0, 32);
|
||||
arrayCopy(s, 0, signature, 32, 32);
|
||||
|
||||
return signature;
|
||||
}
|
||||
|
||||
/// Verify reports whether sig is a valid signature of message by publicKey. It
|
||||
/// will throw ArgumentError if publicKey.bytes.length is not PublicKeySize.
|
||||
bool verify(PublicKey publicKey, Uint8List message, Uint8List sig) {
|
||||
if (publicKey.bytes.length != PublicKeySize) {
|
||||
throw ArgumentError(
|
||||
'ed25519: bad publicKey length ${publicKey.bytes.length}');
|
||||
}
|
||||
if (sig.length != SignatureSize || sig[63] & 224 != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var A = ExtendedGroupElement();
|
||||
var publicKeyBytes = Uint8List.fromList(publicKey.bytes);
|
||||
if (!A.FromBytes(publicKeyBytes)) {
|
||||
return false;
|
||||
}
|
||||
FeNeg(A.X, A.X);
|
||||
FeNeg(A.T, A.T);
|
||||
|
||||
var output = AccumulatorSink<Digest>();
|
||||
var input = sha512.startChunkedConversion(output);
|
||||
input.add(sig.sublist(0, 32));
|
||||
input.add(publicKeyBytes);
|
||||
input.add(message);
|
||||
input.close();
|
||||
var digest = output.events.single.bytes;
|
||||
|
||||
var hReduced = Uint8List(32);
|
||||
ScReduce(hReduced, digest as Uint8List);
|
||||
|
||||
var R = ProjectiveGroupElement();
|
||||
var s = sig.sublist(32);
|
||||
|
||||
if (!ScMinimal(s)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GeDoubleScalarMultVartime(R, hReduced, A, s);
|
||||
|
||||
var checkR = Uint8List(32);
|
||||
R.ToBytes(checkR);
|
||||
return ListEquality().equals(sig.sublist(0, 32), checkR);
|
||||
}
|
||||
10162
ed25519_edwards/lib/src/const.dart
Normal file
10162
ed25519_edwards/lib/src/const.dart
Normal file
File diff suppressed because it is too large
Load diff
2127
ed25519_edwards/lib/src/edwards25519.dart
Normal file
2127
ed25519_edwards/lib/src/edwards25519.dart
Normal file
File diff suppressed because it is too large
Load diff
18
ed25519_edwards/lib/src/numbers.dart
Normal file
18
ed25519_edwards/lib/src/numbers.dart
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import 'package:adaptive_number/adaptive_number.dart';
|
||||
|
||||
abstract class Numbers {
|
||||
static Number v8 = Number(8);
|
||||
static Number v15 = Number(15);
|
||||
static Number v19 = Number(19);
|
||||
static Number v24 = Number(24);
|
||||
static Number v25 = Number(25);
|
||||
static Number v26 = Number(26);
|
||||
static Number v38 = Number(38);
|
||||
static Number v136657 = Number(136657);
|
||||
static Number v2097151 = Number(2097151);
|
||||
static Number v470296 = Number(470296);
|
||||
static Number v683901 = Number(683901);
|
||||
static Number v654183 = Number(654183);
|
||||
static Number v666643 = Number(666643);
|
||||
static Number v997805 = Number(997805);
|
||||
}
|
||||
16
ed25519_edwards/lib/src/util.dart
Normal file
16
ed25519_edwards/lib/src/util.dart
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import 'dart:math';
|
||||
|
||||
import 'dart:typed_data';
|
||||
|
||||
void arrayCopy(List src, int srcPos, List dest, int destPos, int length) {
|
||||
dest.setRange(destPos, length + destPos, src, srcPos);
|
||||
}
|
||||
|
||||
final _defaultSecureRandom = Random.secure();
|
||||
|
||||
void fillBytesWithSecureRandomNumbers(Uint8List bytes, {Random? random}) {
|
||||
random ??= _defaultSecureRandom;
|
||||
for (var i = 0; i < bytes.length; i++) {
|
||||
bytes[i] = random.nextInt(256);
|
||||
}
|
||||
}
|
||||
18
ed25519_edwards/pubspec.yaml
Normal file
18
ed25519_edwards/pubspec.yaml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
name: ed25519_edwards
|
||||
description: Dart port of ed25519 from Go Cryptography ed25519
|
||||
version: 0.3.1
|
||||
homepage: https://github.com/Tougee/ed25519
|
||||
|
||||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
|
||||
dependencies:
|
||||
collection: ^1.15.0
|
||||
crypto: ^3.0.0
|
||||
convert: ^3.0.0
|
||||
adaptive_number: ^1.0.0
|
||||
dev_dependencies:
|
||||
pedantic: ^1.10.0
|
||||
test: ^1.16.4
|
||||
hex: ^0.2.0
|
||||
benchmark_harness: ^2.0.0
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2024 Stefan Humm
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
8
emoji_picker_flutter/android/.gitignore
vendored
8
emoji_picker_flutter/android/.gitignore
vendored
|
|
@ -1,8 +0,0 @@
|
|||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
group 'com.fintasys.emoji_picker_flutter'
|
||||
version '1.0-SNAPSHOT'
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.9.20'
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:8.2.1'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.allprojects {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
// Built-in Kotlin: AGP 9+ provides Kotlin, so only apply KGP on older AGP.
|
||||
// AGP 9 enables Built-in Kotlin by default, but Flutter's AGP 9 migrator writes
|
||||
// android.builtInKotlin=false into gradle.properties while apps/plugins transition,
|
||||
// which leaves nothing to apply the `kotlin {}` extension unless we fall back to KGP.
|
||||
def agpMajorVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0].toInteger()
|
||||
def builtInKotlinDisabled = project.hasProperty('android.builtInKotlin') &&
|
||||
project.property('android.builtInKotlin').toString() == 'false'
|
||||
def appliesLegacyKotlin = agpMajorVersion < 9 || builtInKotlinDisabled
|
||||
if (appliesLegacyKotlin) {
|
||||
apply plugin: 'kotlin-android'
|
||||
}
|
||||
|
||||
android {
|
||||
if (project.android.hasProperty("namespace")) {
|
||||
namespace 'com.fintasys.emoji_picker_flutter'
|
||||
}
|
||||
|
||||
compileSdk = 35
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_17
|
||||
targetCompatibility JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'src/main/kotlin'
|
||||
}
|
||||
defaultConfig {
|
||||
minSdkVersion 21
|
||||
}
|
||||
}
|
||||
|
||||
// Configure the Kotlin JVM target to match compileOptions (Java 17). It is not
|
||||
// inherited from compileOptions automatically, so it must be set on both paths.
|
||||
// Legacy KGP (<2.0) exposes kotlinOptions; Built-in Kotlin (AGP 9+, KGP 2.0+)
|
||||
// exposes the compilerOptions DSL instead.
|
||||
if (appliesLegacyKotlin) {
|
||||
android.kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_17.toString()
|
||||
}
|
||||
} else {
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
if (appliesLegacyKotlin) {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
org.gradle.jvmargs=-Xmx1536M
|
||||
android.useAndroidX=true
|
||||
android.enableJetifier=true
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
|
||||
|
|
@ -1 +0,0 @@
|
|||
rootProject.name = 'emoji_picker_flutter'
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.fintasys.emoji_picker_flutter">
|
||||
</manifest>
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
package com.fintasys.emoji_picker_flutter
|
||||
|
||||
import android.graphics.Paint
|
||||
import androidx.annotation.NonNull
|
||||
import androidx.core.graphics.PaintCompat
|
||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
||||
import io.flutter.plugin.common.MethodCall
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
|
||||
import io.flutter.plugin.common.MethodChannel.Result
|
||||
|
||||
/** EmojiPickerFlutterPlugin */
|
||||
class EmojiPickerFlutterPlugin : FlutterPlugin, MethodCallHandler {
|
||||
/// The MethodChannel that will the communication between Flutter and native Android
|
||||
///
|
||||
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
|
||||
/// when the Flutter Engine is detached from the Activity
|
||||
private lateinit var channel: MethodChannel
|
||||
val paint = Paint()
|
||||
|
||||
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
||||
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "emoji_picker_flutter")
|
||||
channel.setMethodCallHandler(this)
|
||||
}
|
||||
|
||||
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
|
||||
when (call.method) {
|
||||
/// returns list of boolean values that corresponds to the `source` list lenght
|
||||
/// each value indicates whether the `source` emoji is supported on the platform
|
||||
"getSupportedEmojis" -> {
|
||||
val list = call.argument<List<String>>("source")
|
||||
val supportedList: List<Boolean>? = list?.map { s ->
|
||||
PaintCompat.hasGlyph(paint, s)
|
||||
}
|
||||
result.success(supportedList)
|
||||
}
|
||||
else -> {
|
||||
result.notImplemented()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
|
||||
channel.setMethodCallHandler(null)
|
||||
}
|
||||
}
|
||||
40
emoji_picker_flutter/ios/.gitignore
vendored
40
emoji_picker_flutter/ios/.gitignore
vendored
|
|
@ -1,40 +0,0 @@
|
|||
.idea/
|
||||
.vagrant/
|
||||
.sconsign.dblite
|
||||
.svn/
|
||||
|
||||
.DS_Store
|
||||
*.swp
|
||||
profile
|
||||
|
||||
DerivedData/
|
||||
build/
|
||||
GeneratedPluginRegistrant.h
|
||||
GeneratedPluginRegistrant.m
|
||||
|
||||
.generated/
|
||||
|
||||
*.pbxuser
|
||||
*.mode1v3
|
||||
*.mode2v3
|
||||
*.perspectivev3
|
||||
|
||||
!default.pbxuser
|
||||
!default.mode1v3
|
||||
!default.mode2v3
|
||||
!default.perspectivev3
|
||||
|
||||
xcuserdata
|
||||
|
||||
*.moved-aside
|
||||
|
||||
*.pyc
|
||||
*sync/
|
||||
Icon?
|
||||
.tags*
|
||||
|
||||
/Flutter/Generated.xcconfig
|
||||
/Flutter/ephemeral/
|
||||
/Flutter/flutter_export_environment.sh
|
||||
|
||||
.swiftpm/
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
#
|
||||
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
|
||||
# Run `pod lib lint emoji_picker_flutter.podspec` to validate before publishing.
|
||||
#
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'emoji_picker_flutter'
|
||||
s.version = '0.0.1'
|
||||
s.summary = 'Flutter Emoji Picker'
|
||||
s.description = 'Flutter Emoji Picker Plugin'
|
||||
s.homepage = 'https://fintasys.com'
|
||||
s.license = { :file => '../LICENSE', :type => 'MIT' }
|
||||
s.author = { 'Your Company' => 'email@example.com' }
|
||||
s.source = { :path => '.' }
|
||||
s.source_files = 'emoji_picker_flutter/Sources/emoji_picker_flutter/**/*.swift'
|
||||
s.dependency 'Flutter'
|
||||
s.platform = :ios, '11.0'
|
||||
|
||||
# Flutter.framework does not contain a i386 slice.
|
||||
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
|
||||
s.swift_version = '5.0'
|
||||
end
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
// swift-tools-version: 5.9
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "emoji_picker_flutter",
|
||||
platforms: [
|
||||
.iOS("12.0"),
|
||||
.macOS("10.14")
|
||||
],
|
||||
products: [
|
||||
// If the plugin name contains "_", replace with "-" for the library name.
|
||||
.library(name: "emoji-picker-flutter", targets: ["emoji_picker_flutter"])
|
||||
],
|
||||
dependencies: [],
|
||||
targets: [
|
||||
.target(
|
||||
name: "emoji_picker_flutter",
|
||||
dependencies: [],
|
||||
resources: [
|
||||
// TODO: If your plugin requires a privacy manifest
|
||||
// (e.g. if it uses any required reason APIs), update the PrivacyInfo.xcprivacy file
|
||||
// to describe your plugin's privacy impact, and then uncomment this line.
|
||||
// For more information, see:
|
||||
// https://developer.apple.com/documentation/bundleresources/privacy_manifest_files
|
||||
// .process("PrivacyInfo.xcprivacy"),
|
||||
|
||||
// TODO: If you have other resources that need to be bundled with your plugin, refer to
|
||||
// the following instructions to add them:
|
||||
// https://developer.apple.com/documentation/xcode/bundling-resources-with-a-swift-package
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
import Flutter
|
||||
import UIKit
|
||||
|
||||
public class EmojiPickerFlutterPlugin: NSObject, FlutterPlugin {
|
||||
public static func register(with registrar: FlutterPluginRegistrar) {
|
||||
let channel = FlutterMethodChannel(name: "emoji_picker_flutter", binaryMessenger: registrar.messenger())
|
||||
let instance = EmojiPickerFlutterPlugin()
|
||||
registrar.addMethodCallDelegate(instance, channel: channel)
|
||||
}
|
||||
|
||||
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
|
||||
switch call.method {
|
||||
case "getPlatformVersion":
|
||||
result("iOS " + UIDevice.current.systemVersion)
|
||||
default:
|
||||
result(FlutterMethodNotImplemented)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
library;
|
||||
|
||||
export 'package:emoji_picker_flutter/locales/emoji_set.dart';
|
||||
export 'package:emoji_picker_flutter/src/bottom_action_bar/bottom_action_bar.dart';
|
||||
export 'package:emoji_picker_flutter/src/bottom_action_bar/bottom_action_bar_config.dart';
|
||||
export 'package:emoji_picker_flutter/src/bottom_action_bar/default_bottom_action_bar.dart';
|
||||
export 'package:emoji_picker_flutter/src/category_view/category_emoji.dart';
|
||||
export 'package:emoji_picker_flutter/src/category_view/category_extra_tab.dart';
|
||||
export 'package:emoji_picker_flutter/src/category_view/category_icon.dart';
|
||||
export 'package:emoji_picker_flutter/src/category_view/category_icons.dart';
|
||||
export 'package:emoji_picker_flutter/src/category_view/category_view.dart';
|
||||
export 'package:emoji_picker_flutter/src/category_view/category_view_config.dart';
|
||||
export 'package:emoji_picker_flutter/src/category_view/default_category_tab_bar.dart';
|
||||
export 'package:emoji_picker_flutter/src/category_view/default_category_view.dart';
|
||||
export 'package:emoji_picker_flutter/src/category_view/recent_tab_behavior.dart';
|
||||
export 'package:emoji_picker_flutter/src/config.dart';
|
||||
export 'package:emoji_picker_flutter/src/default_emoji_set.dart';
|
||||
export 'package:emoji_picker_flutter/src/emoji.dart';
|
||||
export 'package:emoji_picker_flutter/src/emoji_picker.dart';
|
||||
export 'package:emoji_picker_flutter/src/emoji_picker_controller.dart';
|
||||
export 'package:emoji_picker_flutter/src/emoji_picker_utils.dart';
|
||||
export 'package:emoji_picker_flutter/src/emoji_text_editing_controller.dart';
|
||||
export 'package:emoji_picker_flutter/src/emoji_text_style.dart';
|
||||
export 'package:emoji_picker_flutter/src/emoji_view/default_emoji_picker_view.dart';
|
||||
export 'package:emoji_picker_flutter/src/emoji_view/emoji_container.dart';
|
||||
export 'package:emoji_picker_flutter/src/emoji_view/emoji_picker_view.dart';
|
||||
export 'package:emoji_picker_flutter/src/emoji_view/emoji_view_config.dart';
|
||||
export 'package:emoji_picker_flutter/src/emoji_view_state.dart';
|
||||
export 'package:emoji_picker_flutter/src/recent_emoji.dart';
|
||||
export 'package:emoji_picker_flutter/src/search_view/default_search_view.dart';
|
||||
export 'package:emoji_picker_flutter/src/search_view/search_view.dart';
|
||||
export 'package:emoji_picker_flutter/src/search_view/search_view_config.dart';
|
||||
export 'package:emoji_picker_flutter/src/skin_tones/emoji_skin_tones.dart';
|
||||
export 'package:emoji_picker_flutter/src/skin_tones/skin_tone_config.dart';
|
||||
export 'package:emoji_picker_flutter/src/skin_tones/skin_tone_overlay.dart';
|
||||
export 'package:emoji_picker_flutter/src/skin_tones/triangle_decoration.dart';
|
||||
export 'package:emoji_picker_flutter/src/view_order_config.dart';
|
||||
export 'package:emoji_picker_flutter/src/widgets/backspace_button.dart';
|
||||
export 'package:emoji_picker_flutter/src/widgets/emoji_cell.dart';
|
||||
export 'package:emoji_picker_flutter/src/widgets/search_button.dart';
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'emoji_picker_flutter_platform_interface.dart';
|
||||
|
||||
/// An implementation of [EmojiPickerFlutterPlatform] that uses method channels.
|
||||
class MethodChannelEmojiPickerFlutter extends EmojiPickerFlutterPlatform {
|
||||
/// The method channel used to interact with the native platform.
|
||||
@visibleForTesting
|
||||
final methodChannel = const MethodChannel('emoji_picker_flutter');
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
|
||||
import 'emoji_picker_flutter_method_channel.dart';
|
||||
|
||||
/// EmojiPickerFlutterPlatform
|
||||
abstract class EmojiPickerFlutterPlatform extends PlatformInterface {
|
||||
/// Constructs a EmojiPickerFlutterPlatform.
|
||||
EmojiPickerFlutterPlatform() : super(token: _token);
|
||||
|
||||
static final Object _token = Object();
|
||||
|
||||
static EmojiPickerFlutterPlatform _instance =
|
||||
MethodChannelEmojiPickerFlutter();
|
||||
|
||||
/// The default instance of [EmojiPickerFlutterPlatform] to use.
|
||||
///
|
||||
/// Defaults to [MethodChannelEmojiPickerFlutter].
|
||||
static EmojiPickerFlutterPlatform get instance => _instance;
|
||||
|
||||
/// Platform-specific implementations should set this with their own
|
||||
/// platform-specific class that extends [EmojiPickerFlutterPlatform] when
|
||||
/// they register themselves.
|
||||
static set instance(EmojiPickerFlutterPlatform instance) {
|
||||
PlatformInterface.verifyToken(instance, _token);
|
||||
_instance = instance;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
// In order to *not* need this ignore, consider extracting the "web" version
|
||||
// of your plugin as a separate package, instead of inlining it in the same
|
||||
// package as the core of your plugin.
|
||||
// ignore: avoid_web_libraries_in_flutter
|
||||
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
|
||||
import 'package:web/web.dart' as html show window;
|
||||
|
||||
import 'emoji_picker_platform_interface.dart';
|
||||
|
||||
/// A web implementation of the EmojiPickerPlatform of the EmojiPicker plugin.
|
||||
class EmojiPickerFlutterPluginWeb extends EmojiPickerPlatform {
|
||||
/// Constructs a EmojiPickerFlutterPluginWeb
|
||||
EmojiPickerFlutterPluginWeb();
|
||||
|
||||
/// RegisterWith
|
||||
static void registerWith(Registrar registrar) {
|
||||
EmojiPickerPlatform.instance = EmojiPickerFlutterPluginWeb();
|
||||
}
|
||||
|
||||
/// Returns a [String] containing the version of the platform.
|
||||
@override
|
||||
Future<String?> getPlatformVersion() async {
|
||||
final version = html.window.navigator.userAgent;
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'emoji_picker_platform_interface.dart';
|
||||
|
||||
/// An implementation of [EmojiPickerPlatform] that uses method channels.
|
||||
class MethodChannelEmojiPicker extends EmojiPickerPlatform {
|
||||
/// The method channel used to interact with the native platform.
|
||||
@visibleForTesting
|
||||
final methodChannel = const MethodChannel('emojipicker');
|
||||
|
||||
@override
|
||||
Future<String?> getPlatformVersion() async {
|
||||
final version = await methodChannel.invokeMethod<String>(
|
||||
'getPlatformVersion',
|
||||
);
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
|
||||
import 'emoji_picker_method_channel.dart';
|
||||
|
||||
/// EmojiPickerPlatform
|
||||
abstract class EmojiPickerPlatform extends PlatformInterface {
|
||||
/// Constructs a EmojiPickerPlatform.
|
||||
EmojiPickerPlatform() : super(token: _token);
|
||||
|
||||
static final Object _token = Object();
|
||||
|
||||
static EmojiPickerPlatform _instance = MethodChannelEmojiPicker();
|
||||
|
||||
/// The default instance of [EmojiPickerPlatform] to use.
|
||||
///
|
||||
/// Defaults to [MethodChannelEmojiPicker].
|
||||
static EmojiPickerPlatform get instance => _instance;
|
||||
|
||||
/// Platform-specific implementations should set this with their own
|
||||
/// platform-specific class that extends [EmojiPickerPlatform] when
|
||||
/// they register themselves.
|
||||
static set instance(EmojiPickerPlatform instance) {
|
||||
PlatformInterface.verifyToken(instance, _token);
|
||||
_instance = instance;
|
||||
}
|
||||
|
||||
/// getPlatformVersion
|
||||
Future<String?> getPlatformVersion() {
|
||||
throw UnimplementedError('platformVersion() has not been implemented.');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Default method for locale selection
|
||||
List<CategoryEmoji> getDefaultEmojiLocale(Locale locale) {
|
||||
switch (locale.languageCode) {
|
||||
case 'de':
|
||||
return emojiSetGerman;
|
||||
case 'en':
|
||||
return emojiSetEnglish;
|
||||
case 'es':
|
||||
return emojiSetSpanish;
|
||||
case 'fr':
|
||||
return emojiSetFrance;
|
||||
case 'hi':
|
||||
return emojiSetHindi;
|
||||
case 'it':
|
||||
return emojiSetItalian;
|
||||
case 'ja':
|
||||
return emojiSetJapanese;
|
||||
case 'nl':
|
||||
return emojiSetDutch;
|
||||
case 'pt':
|
||||
return emojiSetPortuguese;
|
||||
case 'ru':
|
||||
return emojiSetRussian;
|
||||
case 'zh':
|
||||
return emojiSetChinese;
|
||||
default:
|
||||
return emojiSetEnglish;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
export 'package:emoji_picker_flutter/locales/emoji_set_de.dart';
|
||||
export 'package:emoji_picker_flutter/locales/emoji_set_en.dart';
|
||||
export 'package:emoji_picker_flutter/locales/emoji_set_es.dart';
|
||||
export 'package:emoji_picker_flutter/locales/emoji_set_fr.dart';
|
||||
export 'package:emoji_picker_flutter/locales/emoji_set_hi.dart';
|
||||
export 'package:emoji_picker_flutter/locales/emoji_set_it.dart';
|
||||
export 'package:emoji_picker_flutter/locales/emoji_set_ja.dart';
|
||||
export 'package:emoji_picker_flutter/locales/emoji_set_nl.dart';
|
||||
export 'package:emoji_picker_flutter/locales/emoji_set_pt.dart';
|
||||
export 'package:emoji_picker_flutter/locales/emoji_set_ru.dart';
|
||||
export 'package:emoji_picker_flutter/locales/emoji_set_zh.dart';
|
||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,22 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Template class for custom implementation
|
||||
abstract class BottomActionBar extends StatefulWidget {
|
||||
/// Constructor
|
||||
const BottomActionBar(
|
||||
this.config,
|
||||
this.state,
|
||||
this.showSearchView, {
|
||||
super.key,
|
||||
});
|
||||
|
||||
/// Config for customizations
|
||||
final Config config;
|
||||
|
||||
/// State that holds current emoji data
|
||||
final EmojiViewState state;
|
||||
|
||||
/// Show Search Bar
|
||||
final VoidCallback showSearchView;
|
||||
}
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Callback function for custom bottom action bar
|
||||
typedef BottomActionBarBuilder =
|
||||
Widget Function(
|
||||
Config config,
|
||||
EmojiViewState state,
|
||||
VoidCallback showSearchView,
|
||||
);
|
||||
|
||||
/// Bottom Action Bar Config
|
||||
class BottomActionBarConfig {
|
||||
/// Constructor
|
||||
const BottomActionBarConfig({
|
||||
this.enabled = true,
|
||||
this.showBackspaceButton = true,
|
||||
this.showSearchViewButton = true,
|
||||
this.backgroundColor = Colors.blue,
|
||||
this.buttonColor = Colors.blue,
|
||||
this.buttonIconColor = Colors.white,
|
||||
this.customBottomActionBar,
|
||||
});
|
||||
|
||||
/// Enable Bottom Action Bar
|
||||
final bool enabled;
|
||||
|
||||
/// Show Backspace button
|
||||
final bool showBackspaceButton;
|
||||
|
||||
/// Show Search View button
|
||||
final bool showSearchViewButton;
|
||||
|
||||
/// Background color of search bar
|
||||
final Color? backgroundColor;
|
||||
|
||||
/// Search Button color
|
||||
final Color buttonColor;
|
||||
|
||||
/// Search Button Icon color
|
||||
final Color buttonIconColor;
|
||||
|
||||
/// Custom search bar
|
||||
/// Hot reload is not supported
|
||||
final BottomActionBarBuilder? customBottomActionBar;
|
||||
|
||||
@override
|
||||
bool operator ==(other) {
|
||||
return (other is BottomActionBarConfig) &&
|
||||
other.enabled == enabled &&
|
||||
other.showBackspaceButton == showBackspaceButton &&
|
||||
other.showSearchViewButton == showSearchViewButton &&
|
||||
other.backgroundColor == backgroundColor &&
|
||||
other.buttonColor == buttonColor &&
|
||||
other.buttonIconColor == buttonIconColor;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
enabled.hashCode ^
|
||||
showBackspaceButton.hashCode ^
|
||||
showSearchViewButton.hashCode ^
|
||||
backgroundColor.hashCode ^
|
||||
buttonColor.hashCode ^
|
||||
buttonIconColor.hashCode;
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Default Bottom Action Bar implementation
|
||||
class DefaultBottomActionBar extends BottomActionBar {
|
||||
/// Constructor
|
||||
const DefaultBottomActionBar(
|
||||
super.config,
|
||||
super.state,
|
||||
super.showSearchView, {
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _DefaultBottomActionBarState();
|
||||
}
|
||||
|
||||
class _DefaultBottomActionBarState extends State<DefaultBottomActionBar> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
color: widget.config.bottomActionBarConfig.backgroundColor,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [_buildSearchViewButton(), _buildBackspaceButton()],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchViewButton() {
|
||||
if (widget.config.bottomActionBarConfig.showSearchViewButton) {
|
||||
return CircleAvatar(
|
||||
backgroundColor: widget.config.bottomActionBarConfig.buttonColor,
|
||||
child: SearchButton(
|
||||
widget.config,
|
||||
widget.showSearchView,
|
||||
widget.config.bottomActionBarConfig.buttonIconColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
Widget _buildBackspaceButton() {
|
||||
if (widget.config.bottomActionBarConfig.showBackspaceButton) {
|
||||
return BackspaceButton(
|
||||
widget.config,
|
||||
widget.state.onBackspacePressed,
|
||||
widget.state.onBackspaceLongPressed,
|
||||
widget.config.bottomActionBarConfig.buttonIconColor,
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
|
||||
/// Container for Category and their emoji
|
||||
class CategoryEmoji {
|
||||
/// Constructor
|
||||
const CategoryEmoji(this.category, this.emoji);
|
||||
|
||||
/// Category instance
|
||||
final Category category;
|
||||
|
||||
/// List of emoji of this category
|
||||
final List<Emoji> emoji;
|
||||
|
||||
/// Copy method
|
||||
CategoryEmoji copyWith({Category? category, List<Emoji>? emoji}) {
|
||||
return CategoryEmoji(category ?? this.category, emoji ?? this.emoji);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
/// Behavior of extra tab
|
||||
enum CategoryExtraTab {
|
||||
/// Don't show extra tab
|
||||
NONE,
|
||||
|
||||
/// Display backspace button in tab bar
|
||||
BACKSPACE,
|
||||
|
||||
/// Display search button in tab bar
|
||||
SEARCH,
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Class that defines the icon representing a [Category]
|
||||
class CategoryIcon {
|
||||
/// Icon of Category
|
||||
const CategoryIcon({
|
||||
required this.icon,
|
||||
this.color = const Color.fromRGBO(211, 211, 211, 1),
|
||||
this.selectedColor = const Color.fromRGBO(178, 178, 178, 1),
|
||||
});
|
||||
|
||||
/// The icon to represent the category
|
||||
final IconData icon;
|
||||
|
||||
/// The default color of the icon
|
||||
final Color color;
|
||||
|
||||
/// The color of the icon once the category is selected
|
||||
final Color selectedColor;
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Class used to define all the [CategoryIcon] shown for each [Category]
|
||||
///
|
||||
/// This allows the keyboard to be personalized by changing icons shown.
|
||||
/// If a [CategoryIcon] is set as null or not defined during initialization,
|
||||
/// the default icons will be used instead
|
||||
class CategoryIcons {
|
||||
/// Constructor
|
||||
const CategoryIcons({
|
||||
this.recentIcon = Icons.access_time,
|
||||
this.smileyIcon = Icons.tag_faces,
|
||||
this.animalIcon = Icons.pets,
|
||||
this.foodIcon = Icons.fastfood,
|
||||
this.activityIcon = Icons.directions_run,
|
||||
this.travelIcon = Icons.location_city,
|
||||
this.objectIcon = Icons.lightbulb_outline,
|
||||
this.symbolIcon = Icons.emoji_symbols,
|
||||
this.flagIcon = Icons.flag,
|
||||
});
|
||||
|
||||
/// Icon for [Category.RECENT]
|
||||
final IconData recentIcon;
|
||||
|
||||
/// Icon for [Category.SMILEYS]
|
||||
final IconData smileyIcon;
|
||||
|
||||
/// Icon for [Category.ANIMALS]
|
||||
final IconData animalIcon;
|
||||
|
||||
/// Icon for [Category.FOODS]
|
||||
final IconData foodIcon;
|
||||
|
||||
/// Icon for [Category.ACTIVITIES]
|
||||
final IconData activityIcon;
|
||||
|
||||
/// Icon for [Category.TRAVEL]
|
||||
final IconData travelIcon;
|
||||
|
||||
/// Icon for [Category.OBJECTS]
|
||||
final IconData objectIcon;
|
||||
|
||||
/// Icon for [Category.SYMBOLS]
|
||||
final IconData symbolIcon;
|
||||
|
||||
/// Icon for [Category.FLAGS]
|
||||
final IconData flagIcon;
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Template class for custom implementation
|
||||
/// Inhert this class to create your own Category view
|
||||
abstract class CategoryView extends StatefulWidget {
|
||||
/// Constructor
|
||||
const CategoryView(
|
||||
this.config,
|
||||
this.state,
|
||||
this.tabController,
|
||||
this.pageController, {
|
||||
super.key,
|
||||
});
|
||||
|
||||
/// Config for customizations
|
||||
final Config config;
|
||||
|
||||
/// State that holds current emoji data
|
||||
final EmojiViewState state;
|
||||
|
||||
/// TabController for Category view
|
||||
final TabController tabController;
|
||||
|
||||
/// Page Controller of Emoji view
|
||||
final PageController pageController;
|
||||
}
|
||||
|
||||
/// Returns the icon for the category
|
||||
IconData getIconForCategory(CategoryIcons categoryIcons, Category category) {
|
||||
switch (category) {
|
||||
case Category.RECENT:
|
||||
return categoryIcons.recentIcon;
|
||||
case Category.SMILEYS:
|
||||
return categoryIcons.smileyIcon;
|
||||
case Category.ANIMALS:
|
||||
return categoryIcons.animalIcon;
|
||||
case Category.FOODS:
|
||||
return categoryIcons.foodIcon;
|
||||
case Category.TRAVEL:
|
||||
return categoryIcons.travelIcon;
|
||||
case Category.ACTIVITIES:
|
||||
return categoryIcons.activityIcon;
|
||||
case Category.OBJECTS:
|
||||
return categoryIcons.objectIcon;
|
||||
case Category.SYMBOLS:
|
||||
return categoryIcons.symbolIcon;
|
||||
case Category.FLAGS:
|
||||
return categoryIcons.flagIcon;
|
||||
}
|
||||
}
|
||||
|
||||
/// Template class for custom implementation
|
||||
/// Inhert this class to create your own category view state
|
||||
class CategoryViewState<T extends CategoryView> extends State<T>
|
||||
with SkinToneOverlayStateMixin {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
throw UnimplementedError('Category View implementation missing');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Callback function for custom category view
|
||||
typedef CategoryViewBuilder =
|
||||
Widget Function(
|
||||
Config config,
|
||||
EmojiViewState state,
|
||||
TabController tabController,
|
||||
PageController pageController,
|
||||
);
|
||||
|
||||
/// Category view Config
|
||||
class CategoryViewConfig {
|
||||
/// Constructor
|
||||
const CategoryViewConfig({
|
||||
this.tabBarHeight = 46.0,
|
||||
this.tabIndicatorAnimDuration = kTabScrollDuration,
|
||||
this.initCategory = Category.RECENT,
|
||||
this.recentTabBehavior = RecentTabBehavior.RECENT,
|
||||
this.extraTab = CategoryExtraTab.NONE,
|
||||
this.backgroundColor = const Color(0xFFEBEFF2),
|
||||
this.indicatorColor = Colors.blue,
|
||||
this.iconColor = Colors.grey,
|
||||
this.iconColorSelected = Colors.blue,
|
||||
this.backspaceColor = Colors.blue,
|
||||
this.dividerColor,
|
||||
this.categoryIcons = const CategoryIcons(),
|
||||
this.customCategoryView,
|
||||
});
|
||||
|
||||
/// Tab bar height
|
||||
final double tabBarHeight;
|
||||
|
||||
/// Duration of tab indicator to animate to next category
|
||||
final Duration tabIndicatorAnimDuration;
|
||||
|
||||
/// The initial [Category] that will be selected
|
||||
/// This [Category] will have its button in the bottombar darkened
|
||||
final Category initCategory;
|
||||
|
||||
/// Behavior of Recent Tab (Recent, Popular)
|
||||
final RecentTabBehavior recentTabBehavior;
|
||||
|
||||
/// Extra tab button in category tab bar
|
||||
final CategoryExtraTab? extraTab;
|
||||
|
||||
/// Background color of TabBar
|
||||
final Color backgroundColor;
|
||||
|
||||
/// The color of the category indicator
|
||||
final Color indicatorColor;
|
||||
|
||||
/// The color of the category icons
|
||||
final Color iconColor;
|
||||
|
||||
/// The color of the category icon when selected
|
||||
final Color iconColorSelected;
|
||||
|
||||
/// The color of the backspace icon button
|
||||
final Color backspaceColor;
|
||||
|
||||
/// Divider color between TabBar and emoji's, use Colors.transparent to remove
|
||||
final Color? dividerColor;
|
||||
|
||||
/// Determines the icon to display for each [Category]
|
||||
final CategoryIcons categoryIcons;
|
||||
|
||||
/// Custom search bar
|
||||
/// Hot reload is not supported
|
||||
final CategoryViewBuilder? customCategoryView;
|
||||
|
||||
@override
|
||||
bool operator ==(other) {
|
||||
return (other is CategoryViewConfig) &&
|
||||
other.tabBarHeight == tabBarHeight &&
|
||||
other.tabIndicatorAnimDuration == tabIndicatorAnimDuration &&
|
||||
other.initCategory == initCategory &&
|
||||
other.recentTabBehavior == recentTabBehavior &&
|
||||
other.extraTab == extraTab &&
|
||||
other.backgroundColor == backgroundColor &&
|
||||
other.indicatorColor == indicatorColor &&
|
||||
other.iconColor == iconColor &&
|
||||
other.iconColorSelected == iconColorSelected &&
|
||||
other.backspaceColor == backspaceColor &&
|
||||
other.dividerColor == dividerColor &&
|
||||
other.categoryIcons == categoryIcons;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
tabBarHeight.hashCode ^
|
||||
tabIndicatorAnimDuration.hashCode ^
|
||||
initCategory.hashCode ^
|
||||
recentTabBehavior.hashCode ^
|
||||
extraTab.hashCode ^
|
||||
backgroundColor.hashCode ^
|
||||
indicatorColor.hashCode ^
|
||||
iconColor.hashCode ^
|
||||
iconColorSelected.hashCode ^
|
||||
backspaceColor.hashCode ^
|
||||
dividerColor.hashCode ^
|
||||
categoryIcons.hashCode;
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Default category tab bar
|
||||
class DefaultCategoryTabBar extends StatelessWidget {
|
||||
/// Constructor
|
||||
const DefaultCategoryTabBar(
|
||||
this.config,
|
||||
this.tabController,
|
||||
this.pageController,
|
||||
this.categoryEmojis,
|
||||
this.closeSkinToneOverlay, {
|
||||
super.key,
|
||||
});
|
||||
|
||||
/// Config
|
||||
final Config config;
|
||||
|
||||
/// Tab controller
|
||||
final TabController tabController;
|
||||
|
||||
/// Page controller
|
||||
final PageController pageController;
|
||||
|
||||
/// Category emojis
|
||||
final List<CategoryEmoji> categoryEmojis;
|
||||
|
||||
/// Close skin tone overlay callback
|
||||
final VoidCallback closeSkinToneOverlay;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
height: config.categoryViewConfig.tabBarHeight,
|
||||
child: TabBar(
|
||||
labelColor: config.categoryViewConfig.iconColorSelected,
|
||||
indicatorColor: config.categoryViewConfig.indicatorColor,
|
||||
unselectedLabelColor: config.categoryViewConfig.iconColor,
|
||||
dividerColor: config.categoryViewConfig.dividerColor,
|
||||
controller: tabController,
|
||||
labelPadding: EdgeInsets.zero,
|
||||
onTap: (index) {
|
||||
closeSkinToneOverlay();
|
||||
pageController.jumpToPage(index);
|
||||
},
|
||||
tabs: categoryEmojis
|
||||
.asMap()
|
||||
.entries
|
||||
.map<Widget>(
|
||||
(item) => _buildCategoryTab(item.key, item.value.category),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCategoryTab(int index, Category category) {
|
||||
return Tab(
|
||||
icon: Icon(
|
||||
getIconForCategory(config.categoryViewConfig.categoryIcons, category),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Default category view
|
||||
class DefaultCategoryView extends CategoryView {
|
||||
/// Constructor
|
||||
const DefaultCategoryView(
|
||||
super.config,
|
||||
super.state,
|
||||
super.tabController,
|
||||
super.pageController, {
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
DefaultCategoryViewState createState() => DefaultCategoryViewState();
|
||||
}
|
||||
|
||||
/// Default Category View State
|
||||
class DefaultCategoryViewState extends CategoryViewState {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
color: widget.config.categoryViewConfig.backgroundColor,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: DefaultCategoryTabBar(
|
||||
widget.config,
|
||||
widget.tabController,
|
||||
widget.pageController,
|
||||
widget.state.categoryEmoji,
|
||||
closeSkinToneOverlay,
|
||||
),
|
||||
),
|
||||
_buildExtraTab(widget.config.categoryViewConfig.extraTab),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildExtraTab(CategoryExtraTab? extraTab) {
|
||||
if (extraTab == CategoryExtraTab.BACKSPACE) {
|
||||
return BackspaceButton(
|
||||
widget.config,
|
||||
widget.state.onBackspacePressed,
|
||||
widget.state.onBackspaceLongPressed,
|
||||
widget.config.categoryViewConfig.backspaceColor,
|
||||
);
|
||||
} else if (extraTab == CategoryExtraTab.SEARCH) {
|
||||
return SearchButton(
|
||||
widget.config,
|
||||
widget.state.onShowSearchView,
|
||||
widget.config.categoryViewConfig.iconColor,
|
||||
);
|
||||
} else {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
/// Behavior of Recent Tab
|
||||
enum RecentTabBehavior {
|
||||
/// Don't show Recent Tab
|
||||
NONE,
|
||||
|
||||
/// Display the last used emoji at the top of the list
|
||||
RECENT,
|
||||
|
||||
/// Display the most often used emoji at the top of the list
|
||||
POPULAR,
|
||||
}
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:emoji_picker_flutter/locales/default_emoji_set_locale.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Number of skin tone icons
|
||||
const kSkinToneCount = 6;
|
||||
|
||||
/// Config for customizations
|
||||
class Config {
|
||||
/// Constructor
|
||||
const Config({
|
||||
this.height = 256,
|
||||
this.checkPlatformCompatibility = true,
|
||||
this.emojiSet = getDefaultEmojiLocale,
|
||||
this.locale = const Locale('en'),
|
||||
this.emojiTextStyle,
|
||||
this.customBackspaceIcon,
|
||||
this.customSearchIcon,
|
||||
this.viewOrderConfig = const ViewOrderConfig(),
|
||||
this.emojiViewConfig = const EmojiViewConfig(),
|
||||
this.skinToneConfig = const SkinToneConfig(),
|
||||
this.categoryViewConfig = const CategoryViewConfig(),
|
||||
this.bottomActionBarConfig = const BottomActionBarConfig(),
|
||||
this.searchViewConfig = const SearchViewConfig(),
|
||||
});
|
||||
|
||||
/// Max Height of the Emoji's view
|
||||
/// If explicitly set to null, the emoji view will not be constrained by
|
||||
/// height
|
||||
final double? height;
|
||||
|
||||
/// Verify that emoji glyph is supported by the platform (Android only)
|
||||
final bool checkPlatformCompatibility;
|
||||
|
||||
/// Useful to provide a customized list of Emoji or add/remove the support
|
||||
/// for specific locales (create similar method as in
|
||||
/// default_emoji_set_locale.dart).
|
||||
/// If not provided, the default emoji set will be used based on the
|
||||
/// locales that are available in the package.
|
||||
final List<CategoryEmoji> Function(Locale locale)? emojiSet;
|
||||
|
||||
/// Locale to choose the fitting language for the emoji set
|
||||
/// This will affect the emoji search results
|
||||
final Locale locale;
|
||||
|
||||
/// Custom emoji text style to apply to emoji characters in the grid
|
||||
///
|
||||
/// If you define a custom fontFamily or use GoogleFonts to set this property
|
||||
/// you can consider to set [checkPlatformCompatibility] to false. It will
|
||||
/// improve initalization performance and prevent technically supported glyphs
|
||||
/// from being filtered out.
|
||||
///
|
||||
/// This has priority over [EmojiViewConfig.emojiSizeMax] if font size is set.
|
||||
final TextStyle? emojiTextStyle;
|
||||
|
||||
/// Custom backspace icon
|
||||
final Icon? customBackspaceIcon;
|
||||
|
||||
/// Custom search icon
|
||||
final Icon? customSearchIcon;
|
||||
|
||||
/// Config the order of the views displayed in the UI
|
||||
/// (category bar, emoji view, search bar)
|
||||
final ViewOrderConfig viewOrderConfig;
|
||||
|
||||
/// Emoji view config
|
||||
final EmojiViewConfig emojiViewConfig;
|
||||
|
||||
/// Skin tone config
|
||||
final SkinToneConfig skinToneConfig;
|
||||
|
||||
/// Category view config
|
||||
final CategoryViewConfig categoryViewConfig;
|
||||
|
||||
/// Search bar config
|
||||
final BottomActionBarConfig bottomActionBarConfig;
|
||||
|
||||
/// Search View config
|
||||
final SearchViewConfig searchViewConfig;
|
||||
|
||||
@override
|
||||
bool operator ==(other) {
|
||||
return (other is Config) &&
|
||||
other.height == height &&
|
||||
other.viewOrderConfig == viewOrderConfig &&
|
||||
other.checkPlatformCompatibility == checkPlatformCompatibility &&
|
||||
other.emojiSet == emojiSet &&
|
||||
other.locale == locale &&
|
||||
other.emojiTextStyle == emojiTextStyle &&
|
||||
other.customBackspaceIcon == customBackspaceIcon &&
|
||||
other.customSearchIcon == customSearchIcon &&
|
||||
other.emojiViewConfig == emojiViewConfig &&
|
||||
other.skinToneConfig == skinToneConfig &&
|
||||
other.bottomActionBarConfig == bottomActionBarConfig &&
|
||||
other.searchViewConfig == searchViewConfig;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
(height?.hashCode ?? 0) ^
|
||||
viewOrderConfig.hashCode ^
|
||||
checkPlatformCompatibility.hashCode ^
|
||||
emojiSet.hashCode ^
|
||||
locale.hashCode ^
|
||||
(emojiTextStyle?.hashCode ?? 0) ^
|
||||
customBackspaceIcon.hashCode ^
|
||||
customSearchIcon.hashCode ^
|
||||
categoryViewConfig.hashCode ^
|
||||
emojiViewConfig.hashCode ^
|
||||
skinToneConfig.hashCode ^
|
||||
bottomActionBarConfig.hashCode ^
|
||||
searchViewConfig.hashCode;
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
export 'io_web.dart' if (dart.library.io) 'dart:io';
|
||||
|
|
@ -1,110 +0,0 @@
|
|||
// ------------------------------------------------------------------
|
||||
// THIS FILE WAS DERIVED FROM SOURCE CODE UNDER THE FOLLOWING LICENSE
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Copyright 2012, the Dart project authors. All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// ---------------------------------------------------------
|
||||
// THIS, DERIVED FILE IS LICENSE UNDER THE FOLLOWING LICENSE
|
||||
// ---------------------------------------------------------
|
||||
// Copyright 2020 terrier989@gmail.com.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import 'package:web/web.dart' as web;
|
||||
|
||||
/// Information about the environment in which the current program is running.
|
||||
///
|
||||
/// Platform provides information such as the operating system,
|
||||
/// the hostname of the computer, the value of environment variables,
|
||||
/// the path to the running program,
|
||||
/// and other global properties of the program being run.
|
||||
class Platform {
|
||||
/// Whether the operating system is a version of
|
||||
/// [Linux](https://en.wikipedia.org/wiki/Linux).
|
||||
///
|
||||
/// This value is `false` if the operating system is a specialized
|
||||
/// version of Linux that identifies itself by a different name,
|
||||
/// for example Android (see [isAndroid]).
|
||||
static final bool isLinux = (operatingSystem == 'linux');
|
||||
|
||||
/// Whether the operating system is a version of
|
||||
/// [macOS](https://en.wikipedia.org/wiki/MacOS).
|
||||
static final bool isMacOS = (operatingSystem == 'macos');
|
||||
|
||||
/// Whether the operating system is a version of
|
||||
/// [Microsoft Windows](https://en.wikipedia.org/wiki/Microsoft_Windows).
|
||||
static final bool isWindows = (operatingSystem == 'windows');
|
||||
|
||||
/// Whether the operating system is a version of
|
||||
/// [Android](https://en.wikipedia.org/wiki/Android_%28operating_system%29).
|
||||
static final bool isAndroid = (operatingSystem == 'android');
|
||||
|
||||
/// Whether the operating system is a version of
|
||||
/// [iOS](https://en.wikipedia.org/wiki/IOS).
|
||||
static final bool isIOS = (operatingSystem == 'ios');
|
||||
|
||||
/// Whether the operating system is a version of
|
||||
/// [Fuchsia](https://en.wikipedia.org/wiki/Google_Fuchsia).
|
||||
static final bool isFuchsia = (operatingSystem == 'fuchsia');
|
||||
|
||||
/// A string representing the operating system or platform.
|
||||
static String get operatingSystem {
|
||||
final s = web.window.navigator.userAgent.toLowerCase();
|
||||
if (s.contains('iphone') ||
|
||||
s.contains('ipad') ||
|
||||
s.contains('ipod') ||
|
||||
s.contains('watch os')) {
|
||||
return 'ios';
|
||||
}
|
||||
if (s.contains('mac os')) {
|
||||
return 'macos';
|
||||
}
|
||||
if (s.contains('fuchsia')) {
|
||||
return 'fuchsia';
|
||||
}
|
||||
if (s.contains('android')) {
|
||||
return 'android';
|
||||
}
|
||||
if (s.contains('linux') || s.contains('cros') || s.contains('chromebook')) {
|
||||
return 'linux';
|
||||
}
|
||||
if (s.contains('windows')) {
|
||||
return 'windows';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,55 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Delimiter for keywords
|
||||
const _keywordDelimiter = ' | ';
|
||||
|
||||
/// A class to store data for each individual emoji
|
||||
@immutable
|
||||
class Emoji {
|
||||
/// Emoji constructor
|
||||
const Emoji(this.emoji, this.name, {this.hasSkinTone = false});
|
||||
|
||||
/// The unicode string for this emoji
|
||||
///
|
||||
/// This is the string that should be displayed to view the emoji
|
||||
final String emoji;
|
||||
|
||||
/// The name or description for this emoji
|
||||
final String name;
|
||||
|
||||
/// Flag if emoji supports multiple skin tones
|
||||
final bool hasSkinTone;
|
||||
|
||||
/// List of keywords that describe the emoji
|
||||
List<String> get keywords => name.split(_keywordDelimiter);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Emoji: $emoji, Name: $name, HasSkinTone: $hasSkinTone';
|
||||
}
|
||||
|
||||
/// Parse Emoji from json
|
||||
static Emoji fromJson(Map<String, dynamic> json) {
|
||||
return Emoji(
|
||||
json['emoji'] as String,
|
||||
json['name'] as String,
|
||||
hasSkinTone: json['hasSkinTone'] != null
|
||||
? json['hasSkinTone'] as bool
|
||||
: false,
|
||||
);
|
||||
}
|
||||
|
||||
/// Encode Emoji to json
|
||||
Map<String, dynamic> toJson() {
|
||||
return {'emoji': emoji, 'name': name, 'hasSkinTone': hasSkinTone};
|
||||
}
|
||||
|
||||
/// Copy method
|
||||
Emoji copyWith({String? name, String? emoji, bool? hasSkinTone}) {
|
||||
return Emoji(
|
||||
emoji ?? this.emoji,
|
||||
name ?? this.name,
|
||||
hasSkinTone: hasSkinTone ?? this.hasSkinTone,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,566 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/locales/default_emoji_set_locale.dart';
|
||||
import 'package:emoji_picker_flutter/src/category_view/category_emoji.dart';
|
||||
import 'package:emoji_picker_flutter/src/category_view/recent_tab_behavior.dart';
|
||||
import 'package:emoji_picker_flutter/src/config.dart';
|
||||
import 'package:emoji_picker_flutter/src/emoji.dart';
|
||||
import 'package:emoji_picker_flutter/src/emoji_picker_controller.dart';
|
||||
import 'package:emoji_picker_flutter/src/emoji_picker_internal_utils.dart';
|
||||
import 'package:emoji_picker_flutter/src/emoji_view/default_emoji_picker_view.dart';
|
||||
import 'package:emoji_picker_flutter/src/emoji_view/emoji_view_config.dart';
|
||||
import 'package:emoji_picker_flutter/src/emoji_view_state.dart';
|
||||
import 'package:emoji_picker_flutter/src/recent_emoji.dart';
|
||||
import 'package:emoji_picker_flutter/src/search_view/default_search_view.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'core/io/io_helper.dart';
|
||||
|
||||
/// All the possible categories that [Emoji] can be put into
|
||||
///
|
||||
/// All [Category] are shown in the category bar
|
||||
enum Category {
|
||||
/// Recent / Popular emojis
|
||||
RECENT,
|
||||
|
||||
/// Smiley emojis
|
||||
SMILEYS,
|
||||
|
||||
/// Animal emojis
|
||||
ANIMALS,
|
||||
|
||||
/// Food emojis
|
||||
FOODS,
|
||||
|
||||
/// Activity emojis
|
||||
ACTIVITIES,
|
||||
|
||||
/// Travel emojis
|
||||
TRAVEL,
|
||||
|
||||
/// Ojects emojis
|
||||
OBJECTS,
|
||||
|
||||
/// Sumbol emojis
|
||||
SYMBOLS,
|
||||
|
||||
/// Flag emojis
|
||||
FLAGS,
|
||||
}
|
||||
|
||||
/// Extension on Category enum to get its name
|
||||
extension CategoryExtension on Category {
|
||||
/// Returns name of Category
|
||||
String get name {
|
||||
switch (this) {
|
||||
case Category.RECENT:
|
||||
return 'recent';
|
||||
case Category.SMILEYS:
|
||||
return 'smileys';
|
||||
case Category.ANIMALS:
|
||||
return 'animals';
|
||||
case Category.FOODS:
|
||||
return 'foods';
|
||||
case Category.ACTIVITIES:
|
||||
return 'activities';
|
||||
case Category.TRAVEL:
|
||||
return 'travel';
|
||||
case Category.OBJECTS:
|
||||
return 'objects';
|
||||
case Category.SYMBOLS:
|
||||
return 'symbols';
|
||||
case Category.FLAGS:
|
||||
return 'flags';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Enum to alter the keyboard button style
|
||||
enum ButtonMode {
|
||||
/// No cell touch effects, uses GestureDetector only. Provides best grid
|
||||
/// scrolling performance
|
||||
NONE,
|
||||
|
||||
/// Android button style - gives the button a splash color with ripple effect
|
||||
MATERIAL,
|
||||
|
||||
/// iOS button style - gives the button a fade out effect when pressed
|
||||
CUPERTINO,
|
||||
}
|
||||
|
||||
/// Callback function for when emoji is selected
|
||||
///
|
||||
/// The function returns the selected [Emoji] as well
|
||||
/// as the [Category] from which it originated
|
||||
/// Category can be null in some cases, for example in search results
|
||||
typedef OnEmojiSelected = void Function(Category? category, Emoji emoji);
|
||||
|
||||
/// Callback from emoji cell to show a skin tone selection overlay
|
||||
typedef OnSkinToneDialogRequested =
|
||||
void Function(
|
||||
Offset emojiBoxPosition,
|
||||
Emoji emoji,
|
||||
double emojiSize,
|
||||
CategoryEmoji? categoryEmoji,
|
||||
);
|
||||
|
||||
/// Callback function for backspace button
|
||||
typedef OnBackspacePressed = void Function();
|
||||
|
||||
/// Callback function for backspace button when long pressed
|
||||
typedef OnBackspaceLongPressed = void Function();
|
||||
|
||||
/// Callback function for category tab changed
|
||||
typedef OnCategoryChanged = void Function(Category category);
|
||||
|
||||
/// The Emoji Keyboard widget
|
||||
///
|
||||
/// This widget displays a grid of [Emoji] sorted by [Category]
|
||||
/// which the user can horizontally scroll through.
|
||||
///
|
||||
/// There is also a bottombar which displays all the possible [Category]
|
||||
/// and allow the user to quickly switch to that [Category]
|
||||
class EmojiPicker extends StatefulWidget {
|
||||
/// EmojiPicker for flutter
|
||||
const EmojiPicker({
|
||||
super.key,
|
||||
this.textEditingController,
|
||||
this.scrollController,
|
||||
this.controller,
|
||||
this.onEmojiSelected,
|
||||
this.onBackspacePressed,
|
||||
this.onCategoryChanged,
|
||||
this.config = const Config(),
|
||||
this.customWidget,
|
||||
});
|
||||
|
||||
/// Custom widget
|
||||
final EmojiViewBuilder? customWidget;
|
||||
|
||||
/// If you provide the [TextEditingController] that is linked to a
|
||||
/// [TextField] this widget handles inserting and deleting for you
|
||||
/// automatically.
|
||||
final TextEditingController? textEditingController;
|
||||
|
||||
/// If you provide the [ScrollController] that is linked to a
|
||||
/// [TextField] this widget handles auto scrolling for you.
|
||||
final ScrollController? scrollController;
|
||||
|
||||
/// Controller for managing the emoji picker state, including
|
||||
/// the currently selected category tab.
|
||||
///
|
||||
/// If provided, this controller allows you to:
|
||||
/// - Read the current selected category programmatically
|
||||
/// - Change the selected category programmatically
|
||||
/// - Listen to category changes
|
||||
///
|
||||
/// If both [controller] and [onCategoryChanged] are provided,
|
||||
/// the controller takes precedence.
|
||||
final EmojiPickerController? controller;
|
||||
|
||||
/// The function called when the emoji is selected
|
||||
final OnEmojiSelected? onEmojiSelected;
|
||||
|
||||
/// The function called when backspace button is pressed
|
||||
final OnBackspacePressed? onBackspacePressed;
|
||||
|
||||
/// The function called when category tab changes
|
||||
final OnCategoryChanged? onCategoryChanged;
|
||||
|
||||
/// Config for customizations
|
||||
final Config config;
|
||||
|
||||
@override
|
||||
EmojiPickerState createState() => EmojiPickerState();
|
||||
}
|
||||
|
||||
/// EmojiPickerState
|
||||
class EmojiPickerState extends State<EmojiPicker> {
|
||||
final List<CategoryEmoji> _categoryEmoji = List.empty(growable: true);
|
||||
List<RecentEmoji> _recentEmoji = List.empty(growable: true);
|
||||
late EmojiViewState _state;
|
||||
|
||||
// Prevent emojis to be reloaded with every build
|
||||
bool _loaded = false;
|
||||
|
||||
// Display Search bar
|
||||
bool _isSearchBarVisible = false;
|
||||
|
||||
// Internal helper
|
||||
final _emojiPickerInternalUtils = EmojiPickerInternalUtils();
|
||||
|
||||
/// Update recentEmoji list from outside using EmojiPickerUtils
|
||||
void updateRecentEmoji(
|
||||
List<RecentEmoji> recentEmoji, {
|
||||
bool refresh = false,
|
||||
}) {
|
||||
_recentEmoji = recentEmoji;
|
||||
// Only mutate the displayed category data when we actually intend to
|
||||
// refresh the UI. `_categoryEmoji` is shared by reference with `_state`,
|
||||
// so mutating it here without a `setState()` would still surface the new
|
||||
// recent list on the next unrelated rebuild triggered by a parent widget
|
||||
// (e.g. the RECENT tab re-ordering under the user). The persisted store is
|
||||
// already updated by the caller, so the change is not lost - it simply
|
||||
// becomes visible on the next explicit refresh instead of leaking early.
|
||||
if (!refresh) {
|
||||
return;
|
||||
}
|
||||
final recentTabIndex = _categoryEmoji.indexWhere(
|
||||
(element) => element.category == Category.RECENT,
|
||||
);
|
||||
if (recentTabIndex != -1) {
|
||||
_categoryEmoji[recentTabIndex] = _categoryEmoji[recentTabIndex].copyWith(
|
||||
emoji: _recentEmoji.map((e) => e.emoji).toList(),
|
||||
);
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_updateEmojis();
|
||||
widget.textEditingController?.addListener(_scrollToCursorAfterTextChange);
|
||||
widget.controller?.addListener(_onControllerChanged);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant EmojiPicker oldWidget) {
|
||||
if (oldWidget.config != widget.config) {
|
||||
// Config changed - rebuild EmojiPickerView completely
|
||||
_loaded = false;
|
||||
_updateEmojis();
|
||||
}
|
||||
// Handle controller changes
|
||||
if (oldWidget.controller != widget.controller) {
|
||||
oldWidget.controller?.removeListener(_onControllerChanged);
|
||||
widget.controller?.addListener(_onControllerChanged);
|
||||
}
|
||||
// Handle text editing controller changes
|
||||
if (oldWidget.textEditingController != widget.textEditingController) {
|
||||
oldWidget.textEditingController?.removeListener(
|
||||
_scrollToCursorAfterTextChange,
|
||||
);
|
||||
widget.textEditingController?.addListener(_scrollToCursorAfterTextChange);
|
||||
}
|
||||
_resetStateWhenOffstage();
|
||||
super.didUpdateWidget(oldWidget);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!_loaded) {
|
||||
return widget.config.emojiViewConfig.loadingIndicator;
|
||||
}
|
||||
if (_isSearchBarVisible) {
|
||||
return _buildSearchBar();
|
||||
}
|
||||
return _buildEmojiView();
|
||||
}
|
||||
|
||||
void _resetStateWhenOffstage() {
|
||||
final offstageParent = context.findAncestorWidgetOfExactType<Offstage>();
|
||||
if (offstageParent != null &&
|
||||
offstageParent.offstage == true &&
|
||||
_isSearchBarVisible) {
|
||||
setState(() {
|
||||
_isSearchBarVisible = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _onBackspacePressed() {
|
||||
if (widget.textEditingController != null) {
|
||||
final controller = widget.textEditingController!;
|
||||
|
||||
final text = controller.value.text;
|
||||
var cursorPosition = controller.selection.base.offset;
|
||||
|
||||
// If cursor is not set, then place it at the end of the textfield
|
||||
if (cursorPosition < 0) {
|
||||
controller.selection = TextSelection(
|
||||
baseOffset: controller.text.length,
|
||||
extentOffset: controller.text.length,
|
||||
);
|
||||
cursorPosition = controller.selection.base.offset;
|
||||
}
|
||||
|
||||
if (cursorPosition >= 0) {
|
||||
final selection = controller.value.selection;
|
||||
final newTextBeforeCursor = selection
|
||||
.textBefore(text)
|
||||
.characters
|
||||
.skipLast(1)
|
||||
.toString();
|
||||
|
||||
controller.value = controller.value.copyWith(
|
||||
text: newTextBeforeCursor + selection.textAfter(text),
|
||||
selection: TextSelection.fromPosition(
|
||||
TextPosition(offset: newTextBeforeCursor.length),
|
||||
),
|
||||
composing: TextRange.collapsed(newTextBeforeCursor.length),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
widget.onBackspacePressed?.call();
|
||||
|
||||
if (widget.textEditingController == null) {
|
||||
_scrollToCursorAfterTextChange();
|
||||
}
|
||||
}
|
||||
|
||||
void _onBackspaceLongPressed() {
|
||||
if (widget.textEditingController != null) {
|
||||
final controller = widget.textEditingController!;
|
||||
|
||||
final text = controller.value.text;
|
||||
var cursorPosition = controller.selection.base.offset;
|
||||
|
||||
// If cursor is not set, then place it at the end of the textfield
|
||||
if (cursorPosition < 0) {
|
||||
controller.selection = TextSelection(
|
||||
baseOffset: controller.text.length,
|
||||
extentOffset: controller.text.length,
|
||||
);
|
||||
cursorPosition = controller.selection.base.offset;
|
||||
}
|
||||
|
||||
if (cursorPosition >= 0) {
|
||||
final selection = controller.value.selection;
|
||||
final newTextBeforeCursor = _deleteWordByWord(
|
||||
selection.textBefore(text).toString(),
|
||||
);
|
||||
controller.value = controller.value.copyWith(
|
||||
text: newTextBeforeCursor + selection.textAfter(text),
|
||||
selection: TextSelection.fromPosition(
|
||||
TextPosition(offset: newTextBeforeCursor.length),
|
||||
),
|
||||
composing: TextRange.collapsed(newTextBeforeCursor.length),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String _deleteWordByWord(String text) {
|
||||
// Trim trailing spaces
|
||||
text = text.trimRight();
|
||||
|
||||
// Find the last space to determine the start of the last word
|
||||
final lastSpaceIndex = text.lastIndexOf(' ');
|
||||
|
||||
// If there is a space, remove the last word and spaces before it
|
||||
if (lastSpaceIndex != -1) {
|
||||
return text.substring(0, lastSpaceIndex).trimRight();
|
||||
}
|
||||
|
||||
// If there is no space, remove the entire text
|
||||
return '';
|
||||
}
|
||||
|
||||
// Add recent emoji handling to tap listener
|
||||
void _onEmojiSelected(Category? category, Emoji emoji) {
|
||||
if (widget.config.categoryViewConfig.recentTabBehavior ==
|
||||
RecentTabBehavior.POPULAR) {
|
||||
_emojiPickerInternalUtils
|
||||
.addEmojiToPopularUsed(emoji: emoji, config: widget.config)
|
||||
.then(
|
||||
(newRecentEmoji) => {
|
||||
// we don't want to rebuild the widget if user is currently on
|
||||
// the RECENT tab, it will make emojis jump since sorting
|
||||
// is based on the use frequency
|
||||
updateRecentEmoji(
|
||||
newRecentEmoji,
|
||||
refresh: category != Category.RECENT,
|
||||
),
|
||||
},
|
||||
);
|
||||
} else if (widget.config.categoryViewConfig.recentTabBehavior ==
|
||||
RecentTabBehavior.RECENT) {
|
||||
_emojiPickerInternalUtils
|
||||
.addEmojiToRecentlyUsed(emoji: emoji, config: widget.config)
|
||||
.then(
|
||||
(newRecentEmoji) => {
|
||||
// we don't want to rebuild the widget if user is currently on
|
||||
// the RECENT tab, it will make emojis jump since sorting
|
||||
// is based on the use frequency
|
||||
updateRecentEmoji(
|
||||
newRecentEmoji,
|
||||
refresh: category != Category.RECENT,
|
||||
),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.textEditingController != null) {
|
||||
// based on https://stackoverflow.com/a/60058972/10975692
|
||||
final controller = widget.textEditingController!;
|
||||
final text = controller.text;
|
||||
final selection = controller.selection;
|
||||
final cursorPosition = controller.selection.base.offset;
|
||||
|
||||
if (cursorPosition < 0) {
|
||||
controller.text += emoji.emoji;
|
||||
widget.onEmojiSelected?.call(category, emoji);
|
||||
return;
|
||||
}
|
||||
|
||||
final newText = text.replaceRange(
|
||||
selection.start,
|
||||
selection.end,
|
||||
emoji.emoji,
|
||||
);
|
||||
final emojiLength = emoji.emoji.length;
|
||||
controller.value = controller.value.copyWith(
|
||||
text: newText,
|
||||
selection: selection.copyWith(
|
||||
baseOffset: selection.start + emojiLength,
|
||||
extentOffset: selection.start + emojiLength,
|
||||
),
|
||||
composing: TextRange.collapsed(newText.length),
|
||||
);
|
||||
}
|
||||
|
||||
widget.onEmojiSelected?.call(category, emoji);
|
||||
|
||||
if (widget.textEditingController == null) {
|
||||
_scrollToCursorAfterTextChange();
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize emoji data
|
||||
Future<void> _updateEmojis() async {
|
||||
_categoryEmoji.clear();
|
||||
if ([
|
||||
RecentTabBehavior.RECENT,
|
||||
RecentTabBehavior.POPULAR,
|
||||
].contains(widget.config.categoryViewConfig.recentTabBehavior)) {
|
||||
final futureOrRecent = _emojiPickerInternalUtils.getRecentEmojis();
|
||||
_recentEmoji = futureOrRecent is List<RecentEmoji>
|
||||
? futureOrRecent
|
||||
: await futureOrRecent;
|
||||
final recentEmojiMap = _recentEmoji.map((e) => e.emoji).toList();
|
||||
_categoryEmoji.add(CategoryEmoji(Category.RECENT, recentEmojiMap));
|
||||
}
|
||||
final data =
|
||||
widget.config.emojiSet?.call(widget.config.locale) ??
|
||||
getDefaultEmojiLocale(widget.config.locale);
|
||||
if (widget.config.checkPlatformCompatibility) {
|
||||
final futureOrCategories = _emojiPickerInternalUtils.filterUnsupported(
|
||||
data,
|
||||
);
|
||||
_categoryEmoji.addAll(
|
||||
futureOrCategories is List<CategoryEmoji>
|
||||
? futureOrCategories
|
||||
: await futureOrCategories,
|
||||
);
|
||||
} else {
|
||||
_categoryEmoji.addAll(data);
|
||||
}
|
||||
_state = EmojiViewState(
|
||||
_categoryEmoji,
|
||||
_onEmojiSelected,
|
||||
_onBackspacePressed,
|
||||
_onBackspaceLongPressed,
|
||||
_showSearchView,
|
||||
_handleCategoryChanged,
|
||||
currentCategory: widget.controller?.currentCategory,
|
||||
);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_loaded = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildSearchBar() {
|
||||
return widget.config.searchViewConfig.customSearchView == null
|
||||
? DefaultSearchView(widget.config, _state, _hideSearchView)
|
||||
: widget.config.searchViewConfig.customSearchView!(
|
||||
widget.config,
|
||||
_state,
|
||||
_hideSearchView,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _wrapScrollBehaviorForPlatforms(Widget child) {
|
||||
return !kIsWeb && Platform.isLinux
|
||||
? ScrollConfiguration(
|
||||
behavior: ScrollConfiguration.of(
|
||||
context,
|
||||
).copyWith(scrollbars: false),
|
||||
child: child,
|
||||
)
|
||||
: child;
|
||||
}
|
||||
|
||||
Widget _buildEmojiView() {
|
||||
final content = widget.customWidget == null
|
||||
? DefaultEmojiPickerView(widget.config, _state, _showSearchView)
|
||||
: widget.customWidget!(widget.config, _state, _showSearchView);
|
||||
|
||||
return _wrapScrollBehaviorForPlatforms(
|
||||
widget.config.height != null
|
||||
? SizedBox(height: widget.config.height, child: content)
|
||||
: content,
|
||||
);
|
||||
}
|
||||
|
||||
void _showSearchView() {
|
||||
setState(() {
|
||||
_isSearchBarVisible = true;
|
||||
});
|
||||
}
|
||||
|
||||
void _hideSearchView() {
|
||||
setState(() {
|
||||
_isSearchBarVisible = false;
|
||||
});
|
||||
}
|
||||
|
||||
void _scrollToCursorAfterTextChange() {
|
||||
if (widget.scrollController != null) {
|
||||
final scrollController = widget.scrollController!;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (scrollController.hasClients) {
|
||||
scrollController.animateTo(
|
||||
scrollController.position.maxScrollExtent,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.ease,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Handler for controller category changes
|
||||
void _onControllerChanged() {
|
||||
// When the controller's category changes programmatically,
|
||||
// navigate the tabbar to the new category without rebuilding
|
||||
if (mounted && _loaded && widget.controller != null) {
|
||||
_state.categoryNavigationNotifier.value =
|
||||
widget.controller!.currentCategory;
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle category changes (both from user interaction and programmatic)
|
||||
void _handleCategoryChanged(Category category) {
|
||||
// Update controller if present
|
||||
widget.controller?.updateCategory(category);
|
||||
|
||||
// Call callback if present and no controller (for backward compatibility)
|
||||
if (widget.controller == null) {
|
||||
widget.onCategoryChanged?.call(category);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.controller?.removeListener(_onControllerChanged);
|
||||
widget.textEditingController?.removeListener(
|
||||
_scrollToCursorAfterTextChange,
|
||||
);
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/src/emoji_picker.dart' show Category;
|
||||
import 'package:flutter/foundation.dart' hide Category;
|
||||
|
||||
/// Controller for EmojiPicker widget that allows reading and changing
|
||||
/// the selected category programmatically.
|
||||
///
|
||||
/// Similar to [TextEditingController], this controller provides:
|
||||
/// - Reading the current selected category
|
||||
/// - Setting the category programmatically
|
||||
/// - Listening to category changes
|
||||
///
|
||||
/// Example usage:
|
||||
/// ```dart
|
||||
/// final controller = EmojiPickerController();
|
||||
///
|
||||
/// // Listen to changes
|
||||
/// controller.addListener(() {
|
||||
/// print('Category changed to: ${controller.currentCategory}');
|
||||
/// });
|
||||
///
|
||||
/// // Set category programmatically
|
||||
/// controller.setCategory(Category.SMILEYS);
|
||||
///
|
||||
/// // Use with EmojiPicker
|
||||
/// EmojiPicker(
|
||||
/// controller: controller,
|
||||
/// // ... other config
|
||||
/// )
|
||||
/// ```
|
||||
class EmojiPickerController extends ChangeNotifier {
|
||||
/// Creates an EmojiPickerController with an optional initial category.
|
||||
/// Defaults to [Category.RECENT] if not specified.
|
||||
EmojiPickerController({Category initialCategory = Category.RECENT})
|
||||
: _currentCategory = initialCategory;
|
||||
|
||||
Category _currentCategory;
|
||||
|
||||
/// The currently selected category.
|
||||
Category get currentCategory => _currentCategory;
|
||||
|
||||
/// Sets the selected category and notifies listeners.
|
||||
///
|
||||
/// This will cause the emoji picker to navigate to the specified category
|
||||
/// if it's currently being used by an EmojiPicker widget.
|
||||
void setCategory(Category category) {
|
||||
if (_currentCategory != category) {
|
||||
_currentCategory = category;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/// Internal method used by EmojiPicker to update the controller
|
||||
/// when the user manually changes categories.
|
||||
///
|
||||
/// This should not be called directly by user code.
|
||||
void updateCategory(Category category) {
|
||||
if (_currentCategory != category) {
|
||||
_currentCategory = category;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a copy of this controller with the same current category.
|
||||
EmojiPickerController copyWith({Category? category}) {
|
||||
return EmojiPickerController(initialCategory: category ?? _currentCategory);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() =>
|
||||
'EmojiPickerController(currentCategory: $_currentCategory)';
|
||||
}
|
||||
|
|
@ -1,227 +0,0 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/foundation.dart' hide Category;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'core/io/io_helper.dart';
|
||||
|
||||
/// Initial value for RecentEmoji
|
||||
const initVal = 1;
|
||||
|
||||
/// Helper class that provides internal usage
|
||||
class EmojiPickerInternalUtils {
|
||||
// Establish communication with native
|
||||
static const _platform = MethodChannel('emoji_picker_flutter');
|
||||
|
||||
static final RegExp _skinToneRegExp = RegExp(SkinTone.values.join('|'));
|
||||
|
||||
/// Caches, per [Category], whether each emoji glyph is supported on the
|
||||
/// platform. Keyed by the emoji string (not the [CategoryEmoji]) so the
|
||||
/// cache stays correct across locales and custom emoji sets, which change
|
||||
/// an emoji's name/keywords but never the glyph or its platform support.
|
||||
static final Map<Category, Map<String, bool>> _emojiSupport = {};
|
||||
|
||||
/// Caches the recently used emojis so that [getRecentEmojis] avoids
|
||||
/// re-reading [SharedPreferences] on subsequent calls. Kept in sync by the
|
||||
/// add/clear methods below.
|
||||
static List<RecentEmoji>? _recentEmojis;
|
||||
|
||||
// Query the native side for which of the given glyphs are supported and
|
||||
// merge the result into the per-category support cache.
|
||||
Future<void> _cacheSupport(CategoryEmoji category, List<Emoji> query) async {
|
||||
final available = (await _platform.invokeListMethod<bool>(
|
||||
'getSupportedEmojis',
|
||||
{'source': query.map((e) => e.emoji).toList(growable: false)},
|
||||
))!;
|
||||
|
||||
final support = _emojiSupport.putIfAbsent(category.category, () => {});
|
||||
for (var i = 0; i < query.length; i++) {
|
||||
support[query[i].emoji] = available[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Filter a category down to the glyphs known to be supported. Every glyph is
|
||||
// expected to be present in the cache by the time this is called.
|
||||
CategoryEmoji _applySupport(CategoryEmoji category) {
|
||||
final support = _emojiSupport[category.category];
|
||||
return category.copyWith(
|
||||
emoji: category.emoji.where((e) => support?[e.emoji] ?? false).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Filters out emojis not supported on the platform
|
||||
///
|
||||
/// Returns synchronously when the support of every requested glyph is
|
||||
/// already cached, so a rebuilt [EmojiPicker] does not have to hit the
|
||||
/// native side again. Glyphs whose support is not yet known (e.g. after a
|
||||
/// locale switch that introduces new glyphs, or a custom emoji set) are
|
||||
/// queried and merged into the cache.
|
||||
FutureOr<List<CategoryEmoji>> filterUnsupported(List<CategoryEmoji> data) {
|
||||
if (kIsWeb || !Platform.isAndroid) {
|
||||
return data;
|
||||
}
|
||||
|
||||
// Collect, per category, the glyphs whose support is not yet cached.
|
||||
final pending = <CategoryEmoji, List<Emoji>>{};
|
||||
for (final cat in data) {
|
||||
final support = _emojiSupport[cat.category];
|
||||
final unknown = support == null
|
||||
? cat.emoji
|
||||
: cat.emoji.where((e) => !support.containsKey(e.emoji)).toList();
|
||||
if (unknown.isNotEmpty) {
|
||||
pending[cat] = unknown;
|
||||
}
|
||||
}
|
||||
|
||||
if (pending.isEmpty) {
|
||||
return [for (final cat in data) _applySupport(cat)];
|
||||
}
|
||||
|
||||
return Future(() async {
|
||||
await Future.wait([
|
||||
for (final entry in pending.entries)
|
||||
_cacheSupport(entry.key, entry.value),
|
||||
]);
|
||||
return [for (final cat in data) _applySupport(cat)];
|
||||
});
|
||||
}
|
||||
|
||||
/// Returns list of recently used emoji from cache
|
||||
///
|
||||
/// Reads from [SharedPreferences] on the first call and reuses the cached
|
||||
/// result afterwards. The cache is kept in sync by [addEmojiToRecentlyUsed],
|
||||
/// [addEmojiToPopularUsed] and [clearRecentEmojisInLocalStorage].
|
||||
FutureOr<List<RecentEmoji>> getRecentEmojis() {
|
||||
if (_recentEmojis != null) {
|
||||
return _recentEmojis!.toList();
|
||||
}
|
||||
|
||||
return Future(() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
var emojiJson = prefs.getString('recent');
|
||||
if (emojiJson == null) {
|
||||
return _recentEmojis = [];
|
||||
}
|
||||
var json = jsonDecode(emojiJson) as List<dynamic>;
|
||||
return _recentEmojis = json
|
||||
.map<RecentEmoji>(RecentEmoji.fromJson)
|
||||
.toList();
|
||||
});
|
||||
}
|
||||
|
||||
/// Add an emoji to recently used list
|
||||
Future<List<RecentEmoji>> addEmojiToRecentlyUsed({
|
||||
required Emoji emoji,
|
||||
Config config = const Config(),
|
||||
}) async {
|
||||
// Remove emoji's skin tone in Recent-Category
|
||||
if (emoji.hasSkinTone) {
|
||||
emoji = removeSkinTone(emoji);
|
||||
}
|
||||
var recentEmoji = await getRecentEmojis();
|
||||
var recentEmojiIndex = recentEmoji.indexWhere(
|
||||
(element) => element.emoji.emoji == emoji.emoji,
|
||||
);
|
||||
if (recentEmojiIndex != -1) {
|
||||
// Already exist in recent list
|
||||
// Remove it
|
||||
recentEmoji.removeAt(recentEmojiIndex);
|
||||
}
|
||||
// Add it first position
|
||||
recentEmoji.insert(0, RecentEmoji(emoji, initVal));
|
||||
|
||||
// Limit entries to recentsLimit
|
||||
recentEmoji = recentEmoji.sublist(
|
||||
0,
|
||||
min(config.emojiViewConfig.recentsLimit, recentEmoji.length),
|
||||
);
|
||||
|
||||
// save locally
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
prefs.setString('recent', jsonEncode(recentEmoji));
|
||||
|
||||
return _recentEmojis = recentEmoji;
|
||||
}
|
||||
|
||||
/// Add an emoji to popular used list or increase its counter
|
||||
Future<List<RecentEmoji>> addEmojiToPopularUsed({
|
||||
required Emoji emoji,
|
||||
Config config = const Config(),
|
||||
}) async {
|
||||
// Remove emoji's skin tone in Recent-Category
|
||||
if (emoji.hasSkinTone) {
|
||||
emoji = removeSkinTone(emoji);
|
||||
}
|
||||
var recentEmoji = await getRecentEmojis();
|
||||
var recentEmojiIndex = recentEmoji.indexWhere(
|
||||
(element) => element.emoji.emoji == emoji.emoji,
|
||||
);
|
||||
if (recentEmojiIndex != -1) {
|
||||
// Already exist in recent list
|
||||
// Just update counter
|
||||
recentEmoji[recentEmojiIndex].counter++;
|
||||
} else if (recentEmoji.length == config.emojiViewConfig.recentsLimit &&
|
||||
config.emojiViewConfig.replaceEmojiOnLimitExceed) {
|
||||
// Replace latest emoji with the fresh one
|
||||
recentEmoji[recentEmoji.length - 1] = RecentEmoji(emoji, initVal);
|
||||
} else {
|
||||
recentEmoji.add(RecentEmoji(emoji, initVal));
|
||||
}
|
||||
|
||||
// Sort by counter desc
|
||||
recentEmoji.sort((a, b) => b.counter - a.counter);
|
||||
|
||||
// Limit entries to recentsLimit
|
||||
recentEmoji = recentEmoji.sublist(
|
||||
0,
|
||||
min(config.emojiViewConfig.recentsLimit, recentEmoji.length),
|
||||
);
|
||||
|
||||
// save locally
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
prefs.setString('recent', jsonEncode(recentEmoji));
|
||||
|
||||
return _recentEmojis = recentEmoji;
|
||||
}
|
||||
|
||||
/// Clears the list of recent emojis in local storage
|
||||
Future<void> clearRecentEmojisInLocalStorage() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
prefs.setString('recent', jsonEncode([]));
|
||||
_recentEmojis = [];
|
||||
}
|
||||
|
||||
/// Returns the last remembered skin tone modifier, or `null` if none stored
|
||||
Future<String?> getRememberedSkinTone() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getString('skin_tone');
|
||||
}
|
||||
|
||||
/// Persists the remembered skin tone modifier. Passing `null` clears it.
|
||||
Future<void> setRememberedSkinTone(String? skinTone) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if (skinTone == null) {
|
||||
await prefs.remove('skin_tone');
|
||||
} else {
|
||||
await prefs.setString('skin_tone', skinTone);
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove skin tone from given emoji
|
||||
Emoji removeSkinTone(Emoji emoji) {
|
||||
return emoji.copyWith(emoji: emoji.emoji.replaceFirst(_skinToneRegExp, ''));
|
||||
}
|
||||
|
||||
/// Clears the in-memory caches. The caches are `static`, so they otherwise
|
||||
/// persist for the lifetime of the isolate and can leak state between test
|
||||
/// cases. Call this in `setUp`/`tearDown` to keep tests isolated.
|
||||
@visibleForTesting
|
||||
static void resetCaches() {
|
||||
_emojiSupport.clear();
|
||||
_recentEmojis = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,253 +0,0 @@
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:emoji_picker_flutter/src/emoji_picker_internal_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Emoji Regex
|
||||
/// Keycap Sequence '((\u0023|\u002a|[\u0030-\u0039])\ufe0f\u20e3){1}'
|
||||
/// Issue: https://github.com/flutter/flutter/issues/36062
|
||||
const EmojiRegex =
|
||||
r'((\u0023|\u002a|[\u0030-\u0039])\ufe0f\u20e3){1}|\p{Emoji}|\u200D|\uFE0F';
|
||||
|
||||
/// Helper class that provides extended usage
|
||||
class EmojiPickerUtils {
|
||||
/// Singleton Constructor
|
||||
factory EmojiPickerUtils() {
|
||||
return _singleton;
|
||||
}
|
||||
|
||||
EmojiPickerUtils._internal();
|
||||
|
||||
static final EmojiPickerUtils _singleton = EmojiPickerUtils._internal();
|
||||
static final RegExp _whitespaceRegExp = RegExp(r'\s+');
|
||||
final List<Emoji> _allAvailableEmojiEntities = [];
|
||||
RegExp? _emojiRegExp;
|
||||
|
||||
/// Returns list of recently used emoji from cache
|
||||
Future<List<RecentEmoji>> getRecentEmojis() =>
|
||||
Future.value(EmojiPickerInternalUtils().getRecentEmojis());
|
||||
|
||||
/// Filters out emojis not supported on the platform
|
||||
Future<List<CategoryEmoji>> filterUnsupported(List<CategoryEmoji> data) =>
|
||||
Future.value(EmojiPickerInternalUtils().filterUnsupported(data));
|
||||
|
||||
/// Search for related emoticons based on keywords
|
||||
Future<List<Emoji>> searchEmoji(
|
||||
String search,
|
||||
List<CategoryEmoji> emojiSet, {
|
||||
bool checkPlatformCompatibility = true,
|
||||
}) async {
|
||||
if (search.isEmpty) return [];
|
||||
|
||||
if (_allAvailableEmojiEntities.isEmpty) {
|
||||
final emojiPickerInternalUtils = EmojiPickerInternalUtils();
|
||||
|
||||
final data = [...emojiSet]
|
||||
..removeWhere((e) => e.category == Category.RECENT);
|
||||
final availableCategoryEmoji = checkPlatformCompatibility
|
||||
? await emojiPickerInternalUtils.filterUnsupported(data)
|
||||
: data;
|
||||
|
||||
// Set all the emoji entities
|
||||
for (var emojis in availableCategoryEmoji) {
|
||||
_allAvailableEmojiEntities.addAll(emojis.emoji);
|
||||
}
|
||||
}
|
||||
|
||||
// Split the input string into a list of lowercase keywords
|
||||
final keywordSet = search
|
||||
.split(_whitespaceRegExp)
|
||||
.where((e) => e.isNotEmpty)
|
||||
.map((e) => e.toLowerCase())
|
||||
.toSet();
|
||||
|
||||
if (keywordSet.isEmpty) return [];
|
||||
|
||||
return _allAvailableEmojiEntities.where((emoji) {
|
||||
// Perform lowercasing of emoji keywords once
|
||||
final emojiKeywordSet = emoji.keywords
|
||||
.map((e) => e.toLowerCase())
|
||||
.toSet();
|
||||
|
||||
// Check if first keyword is a prefix of any emoji keyword
|
||||
final matchFirstKeyword = emojiKeywordSet.any(
|
||||
(emojiKeyword) => emojiKeyword.startsWith(keywordSet.first),
|
||||
);
|
||||
|
||||
var matchKeywords = false;
|
||||
if (matchFirstKeyword) {
|
||||
// Check if each search keyword is a prefix of any emoji keyword
|
||||
// start from second keyword, returns true if empty (only 1 keyword)
|
||||
matchKeywords = keywordSet.skip(1).every((keyword) {
|
||||
return emojiKeywordSet.any(
|
||||
(emojiKeyword) => emojiKeyword.startsWith(keyword),
|
||||
);
|
||||
});
|
||||
} else {
|
||||
matchKeywords = false;
|
||||
}
|
||||
|
||||
// Check for an exact match with emoji character
|
||||
final matchEmoji = emoji.emoji == search.trim();
|
||||
|
||||
return matchKeywords || matchEmoji;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
/// Add an emoji to recently used list or increase its counter
|
||||
Future<void> addEmojiToRecentlyUsed({
|
||||
required GlobalKey<EmojiPickerState> key,
|
||||
required Emoji emoji,
|
||||
Config config = const Config(),
|
||||
}) async {
|
||||
return EmojiPickerInternalUtils()
|
||||
.addEmojiToRecentlyUsed(emoji: emoji, config: config)
|
||||
.then(
|
||||
(recentEmojiList) =>
|
||||
key.currentState?.updateRecentEmoji(recentEmojiList),
|
||||
);
|
||||
}
|
||||
|
||||
/// Produce a list of spans to adjust style for emoji characters.
|
||||
/// Spans enclosing emojis will have [parentStyle] combined with [emojiStyle].
|
||||
/// Other spans will not have an explicit style (this method does not set
|
||||
/// [parentStyle] to the whole text.
|
||||
List<InlineSpan> setEmojiTextStyle(
|
||||
String text, {
|
||||
required TextStyle emojiStyle,
|
||||
TextStyle? parentStyle,
|
||||
}) {
|
||||
final composedEmojiStyle = (parentStyle ?? const TextStyle())
|
||||
.merge(DefaultEmojiTextStyle)
|
||||
.merge(emojiStyle);
|
||||
|
||||
final spans = <TextSpan>[];
|
||||
final matches = getEmojiRegex().allMatches(text).toList();
|
||||
var cursor = 0;
|
||||
for (final match in matches) {
|
||||
if (cursor != match.start) {
|
||||
// Non emoji text + following emoji
|
||||
spans
|
||||
..add(
|
||||
TextSpan(
|
||||
text: text.substring(cursor, match.start),
|
||||
style: parentStyle,
|
||||
),
|
||||
)
|
||||
..add(
|
||||
TextSpan(
|
||||
text: text.substring(match.start, match.end),
|
||||
style: composedEmojiStyle,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
if (spans.isEmpty) {
|
||||
// Create new span if no previous emoji TextSpan exists
|
||||
spans.add(
|
||||
TextSpan(
|
||||
text: text.substring(match.start, match.end),
|
||||
style: composedEmojiStyle,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
// Update last span if current text is still emoji
|
||||
final lastIndex = spans.length - 1;
|
||||
final lastText = spans[lastIndex].text ?? '';
|
||||
final currentText = text.substring(match.start, match.end);
|
||||
spans[lastIndex] = TextSpan(
|
||||
text: '$lastText$currentText',
|
||||
style: composedEmojiStyle,
|
||||
);
|
||||
}
|
||||
}
|
||||
// Update cursor
|
||||
cursor = match.end;
|
||||
}
|
||||
// Add remaining text
|
||||
if (cursor != text.length) {
|
||||
spans.add(
|
||||
TextSpan(text: text.substring(cursor, text.length), style: parentStyle),
|
||||
);
|
||||
}
|
||||
return spans;
|
||||
}
|
||||
|
||||
/// Applies skin tone to given emoji
|
||||
///
|
||||
/// Any existing skin tone modifier is stripped first, so re-applying a tone
|
||||
/// to an already toned glyph produces a valid single-modifier sequence
|
||||
/// instead of an invalid double-modifier one (e.g. 👋🏻🏽).
|
||||
Emoji applySkinTone(Emoji emoji, String color) {
|
||||
final codeUnits = removeSkinTone(emoji).emoji.codeUnits;
|
||||
var result = List<int>.empty(growable: true)
|
||||
// Basic emoji without gender (until char 2)
|
||||
..addAll(codeUnits.sublist(0, min(codeUnits.length, 2)))
|
||||
// Skin tone
|
||||
..addAll(color.codeUnits);
|
||||
// add the rest of the emoji (gender, etc.) again
|
||||
if (codeUnits.length >= 2) {
|
||||
result.addAll(codeUnits.sublist(2));
|
||||
}
|
||||
return emoji.copyWith(emoji: String.fromCharCodes(result));
|
||||
}
|
||||
|
||||
/// Removes any skin tone modifier from the given emoji
|
||||
Emoji removeSkinTone(Emoji emoji) =>
|
||||
EmojiPickerInternalUtils().removeSkinTone(emoji);
|
||||
|
||||
/// Returns the emoji that should be displayed (and selected) in the grid,
|
||||
/// recents and search results.
|
||||
///
|
||||
/// When [skinToneConfig] remembers a tone and [rememberedSkinTone] is set,
|
||||
/// the toned glyph is returned; otherwise the original emoji is returned
|
||||
/// unchanged. The result keeps [Emoji.hasSkinTone] intact so the indicator
|
||||
/// and long-press picker keep working on the cell.
|
||||
Emoji applyDisplaySkinTone(
|
||||
Emoji emoji,
|
||||
SkinToneConfig skinToneConfig,
|
||||
String? rememberedSkinTone,
|
||||
) {
|
||||
if (!skinToneConfig.enabled ||
|
||||
!skinToneConfig.rememberSkinTone ||
|
||||
rememberedSkinTone == null ||
|
||||
!emoji.hasSkinTone) {
|
||||
return emoji;
|
||||
}
|
||||
return applySkinTone(emoji, rememberedSkinTone);
|
||||
}
|
||||
|
||||
/// Returns the skin tone modifier contained in [emoji], or `null` when the
|
||||
/// emoji carries no skin tone.
|
||||
String? extractSkinTone(Emoji emoji) {
|
||||
for (final tone in SkinTone.values) {
|
||||
if (emoji.emoji.contains(tone)) {
|
||||
return tone;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Returns the last remembered skin tone modifier, or `null` if none.
|
||||
Future<String?> getRememberedSkinTone() =>
|
||||
EmojiPickerInternalUtils().getRememberedSkinTone();
|
||||
|
||||
/// Persists the remembered skin tone modifier. Passing `null` clears it.
|
||||
Future<void> setRememberedSkinTone(String? skinTone) =>
|
||||
EmojiPickerInternalUtils().setRememberedSkinTone(skinTone);
|
||||
|
||||
/// Clears the list of recent emojis
|
||||
Future<void> clearRecentEmojis({
|
||||
required GlobalKey<EmojiPickerState> key,
|
||||
}) async {
|
||||
return await EmojiPickerInternalUtils()
|
||||
.clearRecentEmojisInLocalStorage()
|
||||
.then((_) => key.currentState?.updateRecentEmoji([], refresh: true));
|
||||
}
|
||||
|
||||
/// Returns the emoji regex
|
||||
/// Based on https://unicode.org/reports/tr51/
|
||||
RegExp getEmojiRegex() {
|
||||
return _emojiRegExp ??= RegExp(EmojiRegex, unicode: true);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// Default delimiter for regex
|
||||
const delimiter = '|';
|
||||
|
||||
/// Text editing controller that produces text spans on the fly for setting
|
||||
/// a particular style to emoji characters.
|
||||
class EmojiTextEditingController extends TextEditingController {
|
||||
/// Constructor, requres emojiStyle, since otherwise this class has no effect
|
||||
EmojiTextEditingController({super.text, required this.emojiTextStyle});
|
||||
|
||||
/// The style used for the emoji characters
|
||||
final TextStyle emojiTextStyle;
|
||||
|
||||
/// Emoji Picker Utils
|
||||
final EmojiPickerUtils utils = EmojiPickerUtils();
|
||||
|
||||
@override
|
||||
TextSpan buildTextSpan({
|
||||
required BuildContext context,
|
||||
TextStyle? style,
|
||||
required bool withComposing,
|
||||
}) {
|
||||
assert(
|
||||
!value.composing.isValid || !withComposing || value.isComposingRangeValid,
|
||||
);
|
||||
// If the composing range is out of range for the current text, ignore it to
|
||||
// preserve the tree integrity, otherwise in release mode a RangeError will
|
||||
// be thrown and this EditableText will be built with a broken subtree.
|
||||
final composingRegionOutOfRange =
|
||||
!value.isComposingRangeValid || !withComposing;
|
||||
|
||||
// Style when no cursor or selection is set
|
||||
if (composingRegionOutOfRange) {
|
||||
final textSpanChildren = utils.setEmojiTextStyle(
|
||||
text,
|
||||
emojiStyle: emojiTextStyle,
|
||||
parentStyle: style,
|
||||
);
|
||||
return TextSpan(style: style, children: textSpanChildren);
|
||||
}
|
||||
|
||||
// Cursor will automatically highlight current word underlined
|
||||
final underlineStyle =
|
||||
style?.merge(const TextStyle(decoration: TextDecoration.underline)) ??
|
||||
const TextStyle(decoration: TextDecoration.underline);
|
||||
|
||||
return TextSpan(
|
||||
style: style,
|
||||
children: <TextSpan>[
|
||||
TextSpan(
|
||||
children: utils.setEmojiTextStyle(
|
||||
value.composing.textBefore(value.text),
|
||||
emojiStyle: emojiTextStyle,
|
||||
parentStyle: style,
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
children: utils.setEmojiTextStyle(
|
||||
value.composing.textInside(value.text),
|
||||
emojiStyle: emojiTextStyle,
|
||||
parentStyle: underlineStyle,
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
children: utils.setEmojiTextStyle(
|
||||
value.composing.textAfter(value.text),
|
||||
emojiStyle: emojiTextStyle,
|
||||
parentStyle: style,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Emoji text style providing commonly available fallback fonts
|
||||
const DefaultEmojiTextStyle = TextStyle(
|
||||
inherit: true,
|
||||
// Commonly available fallback fonts.
|
||||
fontFamilyFallback: [
|
||||
// iOS and MacOs.
|
||||
'Apple Color Emoji',
|
||||
// Android, ChromeOS, Ubuntu and some other Linux distros.
|
||||
'Noto Color Emoji',
|
||||
// Windows.
|
||||
'Segoe UI Emoji',
|
||||
],
|
||||
);
|
||||
|
|
@ -1,298 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Default EmojiPicker Implementation
|
||||
class DefaultEmojiPickerView extends EmojiPickerView {
|
||||
/// Constructor
|
||||
const DefaultEmojiPickerView(
|
||||
super.config,
|
||||
super.state,
|
||||
super.showSearchBar, {
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<DefaultEmojiPickerView> createState() => _DefaultEmojiPickerViewState();
|
||||
}
|
||||
|
||||
class _DefaultEmojiPickerViewState extends State<DefaultEmojiPickerView>
|
||||
with SingleTickerProviderStateMixin, SkinToneOverlayStateMixin {
|
||||
late TabController _tabController;
|
||||
late PageController _pageController;
|
||||
final _scrollController = ScrollController();
|
||||
final _utils = EmojiPickerUtils();
|
||||
|
||||
/// Last remembered skin tone, applied to skin-tone-capable emoji for
|
||||
/// display and selection when [SkinToneConfig.rememberSkinTone] is enabled.
|
||||
String? _rememberedSkinTone;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// Use controller's current category if available,
|
||||
// otherwise use config's initCategory
|
||||
final targetCategory =
|
||||
widget.state.currentCategory ??
|
||||
widget.config.categoryViewConfig.initCategory;
|
||||
|
||||
var initCategory = widget.state.categoryEmoji.indexWhere(
|
||||
(element) => element.category == targetCategory,
|
||||
);
|
||||
if (initCategory == -1) {
|
||||
initCategory = 0;
|
||||
}
|
||||
_tabController = TabController(
|
||||
initialIndex: initCategory,
|
||||
length: widget.state.categoryEmoji.length,
|
||||
vsync: this,
|
||||
);
|
||||
_pageController = PageController(initialPage: initCategory)
|
||||
..addListener(closeSkinToneOverlay);
|
||||
_scrollController.addListener(closeSkinToneOverlay);
|
||||
|
||||
// Listen to programmatic category changes from controller
|
||||
widget.state.categoryNavigationNotifier.addListener(
|
||||
_onCategoryNavigationChanged,
|
||||
);
|
||||
|
||||
_loadRememberedSkinTone();
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
void _loadRememberedSkinTone() {
|
||||
if (!widget.config.skinToneConfig.rememberSkinTone) {
|
||||
return;
|
||||
}
|
||||
_utils.getRememberedSkinTone().then((tone) {
|
||||
if (!mounted || tone == null) {
|
||||
return;
|
||||
}
|
||||
setState(() => _rememberedSkinTone = tone);
|
||||
});
|
||||
}
|
||||
|
||||
void _onCategoryNavigationChanged() {
|
||||
final targetCategory = widget.state.categoryNavigationNotifier.value;
|
||||
if (targetCategory != null) {
|
||||
final index = widget.state.categoryEmoji.indexWhere(
|
||||
(element) => element.category == targetCategory,
|
||||
);
|
||||
if (index != -1) {
|
||||
final currentPage = _pageController.page?.round();
|
||||
if (index != currentPage) {
|
||||
// Use jumpToPage for instant navigation without building
|
||||
// intermediate pages. This prevents performance issues when
|
||||
// jumping to tabs far away. The onPageChanged callback will
|
||||
// handle animating the tab indicator
|
||||
_pageController.jumpToPage(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.state.categoryNavigationNotifier.removeListener(
|
||||
_onCategoryNavigationChanged,
|
||||
);
|
||||
closeSkinToneOverlay();
|
||||
_pageController.dispose();
|
||||
_scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final emojiSize = widget.config.emojiViewConfig.getEmojiSize(
|
||||
constraints.maxWidth,
|
||||
);
|
||||
final emojiBoxSize = widget.config.emojiViewConfig.getEmojiBoxSize(
|
||||
constraints.maxWidth,
|
||||
);
|
||||
return EmojiContainer(
|
||||
color: widget.config.emojiViewConfig.backgroundColor,
|
||||
buttonMode: widget.config.emojiViewConfig.buttonMode,
|
||||
child: ClipRect(
|
||||
child: Column(
|
||||
children:
|
||||
[
|
||||
widget.config.viewOrderConfig.top,
|
||||
widget.config.viewOrderConfig.middle,
|
||||
widget.config.viewOrderConfig.bottom,
|
||||
].map((item) {
|
||||
switch (item) {
|
||||
case EmojiPickerItem.categoryBar:
|
||||
// Category view
|
||||
return _buildCategoryView();
|
||||
case EmojiPickerItem.emojiView:
|
||||
// Emoji view
|
||||
return _buildEmojiView(emojiSize, emojiBoxSize);
|
||||
case EmojiPickerItem.searchBar:
|
||||
// Search Bar
|
||||
return _buildBottomSearchBar();
|
||||
}
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCategoryView() {
|
||||
return widget.config.categoryViewConfig.customCategoryView != null
|
||||
? widget.config.categoryViewConfig.customCategoryView!(
|
||||
widget.config,
|
||||
widget.state,
|
||||
_tabController,
|
||||
_pageController,
|
||||
)
|
||||
: DefaultCategoryView(
|
||||
widget.config,
|
||||
widget.state,
|
||||
_tabController,
|
||||
_pageController,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmojiView(double emojiSize, double emojiBoxSize) {
|
||||
return Flexible(
|
||||
child: PageView.builder(
|
||||
itemCount: widget.state.categoryEmoji.length,
|
||||
controller: _pageController,
|
||||
onPageChanged: (index) {
|
||||
_tabController.animateTo(
|
||||
index,
|
||||
duration: widget.config.categoryViewConfig.tabIndicatorAnimDuration,
|
||||
);
|
||||
// Notify about category change
|
||||
if (index < widget.state.categoryEmoji.length) {
|
||||
widget.state.onCategoryChanged?.call(
|
||||
widget.state.categoryEmoji[index].category,
|
||||
);
|
||||
}
|
||||
},
|
||||
itemBuilder: (context, index) => _buildPage(
|
||||
emojiSize,
|
||||
emojiBoxSize,
|
||||
widget.state.categoryEmoji[index],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBottomSearchBar() {
|
||||
if (!widget.config.bottomActionBarConfig.enabled) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return widget.config.bottomActionBarConfig.customBottomActionBar != null
|
||||
? widget.config.bottomActionBarConfig.customBottomActionBar!(
|
||||
widget.config,
|
||||
widget.state,
|
||||
widget.showSearchBar,
|
||||
)
|
||||
: DefaultBottomActionBar(
|
||||
widget.config,
|
||||
widget.state,
|
||||
widget.showSearchBar,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPage(
|
||||
double emojiSize,
|
||||
double emojiBoxSize,
|
||||
CategoryEmoji categoryEmoji,
|
||||
) {
|
||||
// Display notice if recent has no entries yet
|
||||
if (categoryEmoji.category == Category.RECENT &&
|
||||
categoryEmoji.emoji.isEmpty) {
|
||||
return _buildNoRecent();
|
||||
}
|
||||
// Build page normally
|
||||
return GridView.builder(
|
||||
key: const Key('emojiScrollView'),
|
||||
scrollDirection: Axis.vertical,
|
||||
controller: _scrollController,
|
||||
primary: false,
|
||||
padding: widget.config.emojiViewConfig.gridPadding,
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
childAspectRatio: 1,
|
||||
crossAxisCount: widget.config.emojiViewConfig.columns,
|
||||
mainAxisSpacing: widget.config.emojiViewConfig.verticalSpacing,
|
||||
crossAxisSpacing: widget.config.emojiViewConfig.horizontalSpacing,
|
||||
),
|
||||
itemCount: categoryEmoji.emoji.length,
|
||||
itemBuilder: (context, index) {
|
||||
// Apply a remembered/default skin tone for display and selection.
|
||||
// Falls back to the base glyph when no tone is configured.
|
||||
final displayEmoji = _utils.applyDisplaySkinTone(
|
||||
categoryEmoji.emoji[index],
|
||||
widget.config.skinToneConfig,
|
||||
_rememberedSkinTone,
|
||||
);
|
||||
return addSkinToneTargetIfAvailable(
|
||||
hasSkinTone: displayEmoji.hasSkinTone,
|
||||
linkKey: categoryEmoji.category.name + displayEmoji.emoji,
|
||||
child: EmojiCell.fromConfig(
|
||||
emoji: displayEmoji,
|
||||
emojiSize: emojiSize,
|
||||
emojiBoxSize: emojiBoxSize,
|
||||
categoryEmoji: categoryEmoji,
|
||||
onEmojiSelected: _onSkinTonedEmojiSelected,
|
||||
onSkinToneDialogRequested: _openSkinToneDialog,
|
||||
config: widget.config,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Build Widget for when no recent emoji are available
|
||||
Widget _buildNoRecent() {
|
||||
return Center(child: widget.config.emojiViewConfig.noRecents);
|
||||
}
|
||||
|
||||
void _openSkinToneDialog(
|
||||
Offset emojiBoxPosition,
|
||||
Emoji emoji,
|
||||
double emojiSize,
|
||||
CategoryEmoji? categoryEmoji,
|
||||
) {
|
||||
closeSkinToneOverlay();
|
||||
if (!emoji.hasSkinTone || !widget.config.skinToneConfig.enabled) {
|
||||
return;
|
||||
}
|
||||
showSkinToneOverlay(
|
||||
emojiBoxPosition,
|
||||
emoji,
|
||||
emojiSize,
|
||||
categoryEmoji,
|
||||
widget.config,
|
||||
_onSkinTonedEmojiSelected,
|
||||
links[categoryEmoji!.category.name + emoji.emoji]!,
|
||||
);
|
||||
}
|
||||
|
||||
void _onSkinTonedEmojiSelected(Category? category, Emoji emoji) {
|
||||
_rememberSkinToneIfEnabled(emoji);
|
||||
widget.state.onEmojiSelected(category, emoji);
|
||||
closeSkinToneOverlay();
|
||||
}
|
||||
|
||||
/// Persists and re-applies the skin tone of the selected [emoji] when
|
||||
/// [SkinToneConfig.rememberSkinTone] is enabled. Selecting a
|
||||
/// skin-tone-capable base glyph (no modifier) clears the remembered tone.
|
||||
void _rememberSkinToneIfEnabled(Emoji emoji) {
|
||||
if (!widget.config.skinToneConfig.rememberSkinTone || !emoji.hasSkinTone) {
|
||||
return;
|
||||
}
|
||||
final tone = _utils.extractSkinTone(emoji);
|
||||
if (tone == _rememberedSkinTone) {
|
||||
return;
|
||||
}
|
||||
_utils.setRememberedSkinTone(tone);
|
||||
setState(() => _rememberedSkinTone = tone);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/src/emoji_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// A wrapper around a grid or list of emojis.
|
||||
/// If the button style is Cupertino or None, this is just wrapping the
|
||||
/// `child` with a container of a provided color.
|
||||
/// For Material style it is a `Material` widget that allows to render
|
||||
/// touch response for individual InkWell cells.
|
||||
class EmojiContainer extends StatelessWidget {
|
||||
/// Constructor
|
||||
const EmojiContainer({
|
||||
super.key,
|
||||
required this.color,
|
||||
required this.buttonMode,
|
||||
this.padding,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
/// Background color for container
|
||||
final Color color;
|
||||
|
||||
/// Button mode that affects the type of container
|
||||
final ButtonMode buttonMode;
|
||||
|
||||
/// Optional padding
|
||||
final EdgeInsets? padding;
|
||||
|
||||
/// Child widget
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (buttonMode == ButtonMode.MATERIAL) {
|
||||
return Material(
|
||||
color: color,
|
||||
child: padding == null
|
||||
? child
|
||||
: Padding(padding: padding!, child: child),
|
||||
);
|
||||
} else {
|
||||
return Container(color: color, padding: padding, child: child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/src/config.dart';
|
||||
import 'package:emoji_picker_flutter/src/emoji_view_state.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Template class for custom implementation
|
||||
/// Inhert this class to create your own EmojiPicker
|
||||
abstract class EmojiPickerView extends StatefulWidget {
|
||||
/// Constructor
|
||||
const EmojiPickerView(
|
||||
this.config,
|
||||
this.state,
|
||||
this.showSearchBar, {
|
||||
super.key,
|
||||
});
|
||||
|
||||
/// Config for customizations
|
||||
final Config config;
|
||||
|
||||
/// State that holds current emoji data
|
||||
final EmojiViewState state;
|
||||
|
||||
/// Show Search Bar
|
||||
final VoidCallback showSearchBar;
|
||||
}
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Callback function for custom view
|
||||
typedef EmojiViewBuilder =
|
||||
Widget Function(
|
||||
Config config,
|
||||
EmojiViewState state,
|
||||
VoidCallback showSearchBar,
|
||||
);
|
||||
|
||||
/// Default Widget if no recent is available
|
||||
const DefaultNoRecentsWidget = Text(
|
||||
'No Recents',
|
||||
style: TextStyle(fontSize: 20, color: Colors.black26),
|
||||
textAlign: TextAlign.center,
|
||||
);
|
||||
|
||||
/// Emoji View Config
|
||||
class EmojiViewConfig {
|
||||
/// Constructor
|
||||
const EmojiViewConfig({
|
||||
this.columns = 10,
|
||||
this.emojiSizeMax = 28.0,
|
||||
this.backgroundColor = const Color(0xFFEBEFF2),
|
||||
this.verticalSpacing = 0,
|
||||
this.horizontalSpacing = 0,
|
||||
this.gridPadding = EdgeInsets.zero,
|
||||
this.recentsLimit = 28,
|
||||
this.replaceEmojiOnLimitExceed = false,
|
||||
this.noRecents = DefaultNoRecentsWidget,
|
||||
this.loadingIndicator = const SizedBox.shrink(),
|
||||
this.buttonMode = ButtonMode.MATERIAL,
|
||||
});
|
||||
|
||||
/// Number of emojis per row
|
||||
final int columns;
|
||||
|
||||
/// Width and height the emoji will be maximal displayed
|
||||
/// Can be smaller due to screen size and amount of columns
|
||||
final double emojiSizeMax;
|
||||
|
||||
/// The background color of the emoji view
|
||||
final Color backgroundColor;
|
||||
|
||||
/// Verical spacing between emojis
|
||||
final double verticalSpacing;
|
||||
|
||||
/// Horizontal spacing between emojis
|
||||
final double horizontalSpacing;
|
||||
|
||||
/// Limit of recently used emoji that will be saved
|
||||
final int recentsLimit;
|
||||
|
||||
/// A widget (usually [Text]) to be displayed if no recent emojis to display
|
||||
/// Hot reload is not supported
|
||||
final Widget noRecents;
|
||||
|
||||
/// A widget to display while emoji picker is initializing
|
||||
/// Hot reload is not supported
|
||||
final Widget loadingIndicator;
|
||||
|
||||
/// Choose visual response for tapping on an emoji cell
|
||||
final ButtonMode buttonMode;
|
||||
|
||||
/// The padding of GridView, default is [EdgeInsets.zero]
|
||||
final EdgeInsets gridPadding;
|
||||
|
||||
/// Replace latest emoji on recents list on limit exceed
|
||||
final bool replaceEmojiOnLimitExceed;
|
||||
|
||||
/// Get Emoji size based on properties and screen width
|
||||
double getEmojiSize(double width) {
|
||||
final maxSize = getEmojiBoxSize(width);
|
||||
return min(maxSize, emojiSizeMax);
|
||||
}
|
||||
|
||||
/// Get Emoji hitbox size based on properties and screen width
|
||||
double getEmojiBoxSize(double width) {
|
||||
final totalHorizontalSpacing = (columns - 1) * horizontalSpacing;
|
||||
final availableWidth = width - totalHorizontalSpacing;
|
||||
return availableWidth / columns;
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(other) {
|
||||
return (other is EmojiViewConfig) &&
|
||||
other.columns == columns &&
|
||||
other.emojiSizeMax == emojiSizeMax &&
|
||||
other.backgroundColor == backgroundColor &&
|
||||
other.verticalSpacing == verticalSpacing &&
|
||||
other.horizontalSpacing == horizontalSpacing &&
|
||||
other.recentsLimit == recentsLimit &&
|
||||
other.buttonMode == buttonMode &&
|
||||
other.gridPadding == gridPadding &&
|
||||
other.replaceEmojiOnLimitExceed == replaceEmojiOnLimitExceed;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
columns.hashCode ^
|
||||
emojiSizeMax.hashCode ^
|
||||
backgroundColor.hashCode ^
|
||||
verticalSpacing.hashCode ^
|
||||
horizontalSpacing.hashCode ^
|
||||
recentsLimit.hashCode ^
|
||||
buttonMode.hashCode ^
|
||||
gridPadding.hashCode ^
|
||||
replaceEmojiOnLimitExceed.hashCode;
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// State that holds current emoji data
|
||||
class EmojiViewState {
|
||||
/// Constructor
|
||||
EmojiViewState(
|
||||
this.categoryEmoji,
|
||||
this.onEmojiSelected,
|
||||
this.onBackspacePressed,
|
||||
this.onBackspaceLongPressed,
|
||||
this.onShowSearchView,
|
||||
this.onCategoryChanged, {
|
||||
this.currentCategory,
|
||||
});
|
||||
|
||||
/// List of all category including their emoji
|
||||
final List<CategoryEmoji> categoryEmoji;
|
||||
|
||||
/// Callback when pressed on emoji
|
||||
final OnEmojiSelected onEmojiSelected;
|
||||
|
||||
/// Callback when pressed on backspace
|
||||
final OnBackspacePressed? onBackspacePressed;
|
||||
|
||||
/// Callback when long pressed on backspace
|
||||
final OnBackspaceLongPressed onBackspaceLongPressed;
|
||||
|
||||
/// Callback when pressed on search
|
||||
final VoidCallback onShowSearchView;
|
||||
|
||||
/// Callback when category tab changes
|
||||
final OnCategoryChanged? onCategoryChanged;
|
||||
|
||||
/// Current category from controller (if available)
|
||||
/// Used to override the config's initCategory
|
||||
final Category? currentCategory;
|
||||
|
||||
/// Notifier for programmatic category changes from controller
|
||||
/// When this changes, the tabbar should navigate to the new category
|
||||
/// without rebuilding the entire widget
|
||||
final ValueNotifier<Category?> categoryNavigationNotifier =
|
||||
ValueNotifier<Category?>(null);
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/src/emoji.dart';
|
||||
|
||||
/// Class that holds an recent emoji
|
||||
/// Recent Emoji has an instance of the emoji
|
||||
/// And a counter, which counts how often this emoji
|
||||
/// has been used before
|
||||
class RecentEmoji {
|
||||
/// Constructor
|
||||
RecentEmoji(this.emoji, this.counter);
|
||||
|
||||
/// Emoji instance
|
||||
final Emoji emoji;
|
||||
|
||||
/// Counter how often emoji has been used before
|
||||
int counter = 0;
|
||||
|
||||
/// Parse RecentEmoji from json
|
||||
static RecentEmoji fromJson(dynamic json) {
|
||||
return RecentEmoji(
|
||||
Emoji.fromJson(json['emoji'] as Map<String, dynamic>),
|
||||
json['counter'] as int,
|
||||
);
|
||||
}
|
||||
|
||||
/// Encode RecentEmoji to json
|
||||
Map<String, dynamic> toJson() => {'emoji': emoji, 'counter': counter};
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Default Search implementation
|
||||
class DefaultSearchView extends SearchView {
|
||||
/// Constructor
|
||||
const DefaultSearchView(
|
||||
super.config,
|
||||
super.state,
|
||||
super.showEmojiView, {
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
DefaultSearchViewState createState() => DefaultSearchViewState();
|
||||
}
|
||||
|
||||
/// Default Search View State
|
||||
class DefaultSearchViewState extends SearchViewState {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final emojiSize = widget.config.emojiViewConfig.getEmojiSize(
|
||||
constraints.maxWidth,
|
||||
);
|
||||
final emojiBoxSize = widget.config.emojiViewConfig.getEmojiBoxSize(
|
||||
constraints.maxWidth,
|
||||
);
|
||||
|
||||
return Container(
|
||||
color: widget.config.searchViewConfig.backgroundColor,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Material(
|
||||
color: Colors.transparent,
|
||||
child: SizedBox(
|
||||
height: emojiBoxSize + 8.0,
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: results.length,
|
||||
itemBuilder: (context, index) {
|
||||
return buildEmoji(
|
||||
results[index],
|
||||
emojiSize,
|
||||
emojiBoxSize,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
widget.showEmojiView();
|
||||
},
|
||||
color: widget.config.searchViewConfig.buttonIconColor,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
onChanged: onTextInputChanged,
|
||||
focusNode: focusNode,
|
||||
style: widget.config.searchViewConfig.inputTextStyle,
|
||||
decoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
hintText: widget.config.searchViewConfig.hintText,
|
||||
hintStyle: widget.config.searchViewConfig.hintTextStyle,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,170 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:emoji_picker_flutter/src/emoji_picker_internal_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Template class for custom implementation
|
||||
/// Inhert this class to create your own search view
|
||||
abstract class SearchView extends StatefulWidget {
|
||||
/// Constructor
|
||||
const SearchView(this.config, this.state, this.showEmojiView, {super.key});
|
||||
|
||||
/// Config for customizations
|
||||
final Config config;
|
||||
|
||||
/// State that holds current emoji data
|
||||
final EmojiViewState state;
|
||||
|
||||
/// Return to emoji view
|
||||
final VoidCallback showEmojiView;
|
||||
}
|
||||
|
||||
/// Template class for custom implementation
|
||||
/// Inhert this class to create your own search view state
|
||||
class SearchViewState<T extends SearchView> extends State<T>
|
||||
with SkinToneOverlayStateMixin {
|
||||
/// Emoji picker utils
|
||||
final utils = EmojiPickerUtils();
|
||||
|
||||
/// Internal utils, used for the cache-backed synchronous fast-path when
|
||||
/// loading recent emojis (the public [utils] returns a `Future`).
|
||||
final _internalUtils = EmojiPickerInternalUtils();
|
||||
|
||||
/// Focus node for textfield
|
||||
final focusNode = FocusNode();
|
||||
|
||||
/// Search results
|
||||
final results = List<Emoji>.empty(growable: true);
|
||||
|
||||
/// Last remembered skin tone, applied to skin-tone-capable emoji for display
|
||||
/// and selection when [SkinToneConfig.rememberSkinTone] is enabled.
|
||||
String? _rememberedSkinTone;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadRememberedSkinTone();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
// Auto focus textfield
|
||||
FocusScope.of(context).requestFocus(focusNode);
|
||||
// Load recent emojis initially
|
||||
final futureOrRecent = _internalUtils.getRecentEmojis();
|
||||
if (futureOrRecent is List<RecentEmoji>) {
|
||||
setState(
|
||||
() => _updateResults(futureOrRecent.map((e) => e.emoji).toList()),
|
||||
);
|
||||
} else {
|
||||
futureOrRecent.then((value) {
|
||||
if (!mounted) return;
|
||||
setState(() => _updateResults(value.map((e) => e.emoji).toList()));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
focusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _loadRememberedSkinTone() {
|
||||
if (!widget.config.skinToneConfig.rememberSkinTone) {
|
||||
return;
|
||||
}
|
||||
utils.getRememberedSkinTone().then((tone) {
|
||||
if (!mounted || tone == null) {
|
||||
return;
|
||||
}
|
||||
setState(() => _rememberedSkinTone = tone);
|
||||
});
|
||||
}
|
||||
|
||||
/// On text input changed callback
|
||||
void onTextInputChanged(String text) {
|
||||
links.clear();
|
||||
results.clear();
|
||||
utils.searchEmoji(text, widget.state.categoryEmoji).then((value) {
|
||||
if (!mounted) return;
|
||||
setState(() => _updateResults(value));
|
||||
});
|
||||
}
|
||||
|
||||
void _updateResults(List<Emoji> emojis) {
|
||||
results
|
||||
..clear()
|
||||
..addAll(emojis);
|
||||
results.asMap().entries.forEach((e) {
|
||||
final displayEmoji = utils.applyDisplaySkinTone(
|
||||
e.value,
|
||||
widget.config.skinToneConfig,
|
||||
_rememberedSkinTone,
|
||||
);
|
||||
links[displayEmoji.emoji] = LayerLink();
|
||||
});
|
||||
}
|
||||
|
||||
/// Build emoji cell
|
||||
Widget buildEmoji(Emoji emoji, double emojiSize, double emojiBoxSize) {
|
||||
// Apply a remembered skin tone for display and selection.
|
||||
// Falls back to the base glyph when no tone is remembered.
|
||||
final displayEmoji = utils.applyDisplaySkinTone(
|
||||
emoji,
|
||||
widget.config.skinToneConfig,
|
||||
_rememberedSkinTone,
|
||||
);
|
||||
return addSkinToneTargetIfAvailable(
|
||||
hasSkinTone: displayEmoji.hasSkinTone,
|
||||
linkKey: displayEmoji.emoji,
|
||||
child: EmojiCell.fromConfig(
|
||||
emoji: displayEmoji,
|
||||
emojiSize: emojiSize,
|
||||
emojiBoxSize: emojiBoxSize,
|
||||
onEmojiSelected: widget.state.onEmojiSelected,
|
||||
config: widget.config,
|
||||
onSkinToneDialogRequested:
|
||||
(emojiBoxPosition, emoji, emojiSize, category) {
|
||||
closeSkinToneOverlay();
|
||||
if (!emoji.hasSkinTone || !widget.config.skinToneConfig.enabled) {
|
||||
return;
|
||||
}
|
||||
showSkinToneOverlay(
|
||||
emojiBoxPosition,
|
||||
emoji,
|
||||
emojiSize,
|
||||
null, // Todo: check if we can provide the category
|
||||
widget.config,
|
||||
_onSkinTonedEmojiSelected,
|
||||
links[emoji.emoji]!,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onSkinTonedEmojiSelected(Category? category, Emoji emoji) {
|
||||
_rememberSkinToneIfEnabled(emoji);
|
||||
widget.state.onEmojiSelected(category, emoji);
|
||||
closeSkinToneOverlay();
|
||||
}
|
||||
|
||||
/// Persists and re-applies the skin tone of the selected [emoji] when
|
||||
/// [SkinToneConfig.rememberSkinTone] is enabled. Selecting a
|
||||
/// skin-tone-capable base glyph (no modifier) clears the remembered tone.
|
||||
void _rememberSkinToneIfEnabled(Emoji emoji) {
|
||||
if (!widget.config.skinToneConfig.rememberSkinTone || !emoji.hasSkinTone) {
|
||||
return;
|
||||
}
|
||||
final tone = utils.extractSkinTone(emoji);
|
||||
if (tone == _rememberedSkinTone) {
|
||||
return;
|
||||
}
|
||||
utils.setRememberedSkinTone(tone);
|
||||
setState(() => _rememberedSkinTone = tone);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
throw UnimplementedError('Search View implementation missing');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Callback function for custom search view
|
||||
typedef SearchViewBuilder =
|
||||
Widget Function(
|
||||
Config config,
|
||||
EmojiViewState state,
|
||||
VoidCallback showEmojiView,
|
||||
);
|
||||
|
||||
/// Search view Config
|
||||
class SearchViewConfig {
|
||||
/// Constructor
|
||||
const SearchViewConfig({
|
||||
this.backgroundColor = const Color(0xFFEBEFF2),
|
||||
this.buttonIconColor = Colors.black26,
|
||||
this.inputTextStyle,
|
||||
this.hintText = 'Search',
|
||||
this.hintTextStyle,
|
||||
this.customSearchView,
|
||||
});
|
||||
|
||||
/// Background color of search bar
|
||||
final Color backgroundColor;
|
||||
|
||||
/// Icon color of hide search view button
|
||||
final Color buttonIconColor;
|
||||
|
||||
/// Inpit text style
|
||||
final TextStyle? inputTextStyle;
|
||||
|
||||
/// Custom hint text
|
||||
final String? hintText;
|
||||
|
||||
/// Custom hint text style
|
||||
final TextStyle? hintTextStyle;
|
||||
|
||||
/// Custom search bar
|
||||
/// Hot reload is not supported
|
||||
final SearchViewBuilder? customSearchView;
|
||||
|
||||
@override
|
||||
bool operator ==(other) {
|
||||
return (other is SearchViewConfig) &&
|
||||
other.backgroundColor == backgroundColor &&
|
||||
other.buttonIconColor == buttonIconColor &&
|
||||
other.hintText == hintText &&
|
||||
other.hintTextStyle == hintTextStyle &&
|
||||
other.inputTextStyle == inputTextStyle;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
backgroundColor.hashCode ^
|
||||
buttonIconColor.hashCode ^
|
||||
hintText.hashCode ^
|
||||
hintTextStyle.hashCode ^
|
||||
inputTextStyle.hashCode;
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
/// Alternative skin tones of Emoji
|
||||
class SkinTone {
|
||||
SkinTone._();
|
||||
|
||||
/// Light Skin Tone
|
||||
static const String light = '🏻';
|
||||
|
||||
/// Medium-Light Skin Tone
|
||||
static const String mediumLight = '🏼';
|
||||
|
||||
/// Medium Skin Tone
|
||||
static const String medium = '🏽';
|
||||
|
||||
/// Medium-Dark Skin Tone
|
||||
static const String mediumDark = '🏾';
|
||||
|
||||
/// Dark Skin Tone
|
||||
static const String dark = '🏿';
|
||||
|
||||
/// Return all values as Array
|
||||
static const values = [light, mediumLight, medium, mediumDark, dark];
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Skin tone config Config
|
||||
class SkinToneConfig {
|
||||
/// Constructor
|
||||
const SkinToneConfig({
|
||||
this.enabled = true,
|
||||
this.dialogBackgroundColor = Colors.white,
|
||||
this.indicatorColor = Colors.grey,
|
||||
this.rememberSkinTone = false,
|
||||
});
|
||||
|
||||
/// Enable feature to select a skin tone of certain emoji's
|
||||
final bool enabled;
|
||||
|
||||
/// The background color of the skin tone dialog
|
||||
final Color dialogBackgroundColor;
|
||||
|
||||
/// Color of the small triangle next to multiple skin tone emoji
|
||||
final Color indicatorColor;
|
||||
|
||||
/// Remember the last skin tone the user selected.
|
||||
///
|
||||
/// When `true`, the tone chosen via the long-press picker is persisted (in
|
||||
/// `SharedPreferences`) and re-applied as the default for every
|
||||
/// skin-tone-capable emoji in the grid, recents and search on the next
|
||||
/// launch. Selecting the base (no-tone) glyph clears the remembered tone.
|
||||
///
|
||||
/// When `false` (default) the base glyph is always shown, which is the
|
||||
/// previous behavior.
|
||||
final bool rememberSkinTone;
|
||||
|
||||
@override
|
||||
bool operator ==(other) {
|
||||
return (other is SkinToneConfig) &&
|
||||
other.enabled == enabled &&
|
||||
other.dialogBackgroundColor == dialogBackgroundColor &&
|
||||
other.indicatorColor == indicatorColor &&
|
||||
other.rememberSkinTone == rememberSkinTone;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
enabled.hashCode ^
|
||||
dialogBackgroundColor.hashCode ^
|
||||
indicatorColor.hashCode ^
|
||||
rememberSkinTone.hashCode;
|
||||
}
|
||||
|
|
@ -1,150 +0,0 @@
|
|||
import 'dart:collection';
|
||||
|
||||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Skin tone overlay mixin
|
||||
mixin SkinToneOverlayStateMixin<T extends StatefulWidget> on State<T> {
|
||||
final _utils = EmojiPickerUtils();
|
||||
OverlayEntry? _overlay;
|
||||
|
||||
/// Layer links for skin tone overlay
|
||||
final links = HashMap<String, LayerLink>();
|
||||
|
||||
/// Add target for skin tone overlay if skin tone is available
|
||||
Widget addSkinToneTargetIfAvailable({
|
||||
required bool hasSkinTone,
|
||||
required String linkKey,
|
||||
required Widget child,
|
||||
}) {
|
||||
if (hasSkinTone) {
|
||||
final link = links.putIfAbsent(linkKey, LayerLink.new);
|
||||
return CompositedTransformTarget(link: link, child: child);
|
||||
}
|
||||
return child;
|
||||
}
|
||||
|
||||
/// Overlay close & resources disposal
|
||||
void closeSkinToneOverlay() {
|
||||
_overlay?.remove();
|
||||
_overlay = null;
|
||||
}
|
||||
|
||||
/// Overlay for SkinTone
|
||||
void showSkinToneOverlay(
|
||||
Offset emojiBoxPosition,
|
||||
Emoji emoji,
|
||||
double emojiSize,
|
||||
CategoryEmoji? categoryEmoji,
|
||||
Config config,
|
||||
OnEmojiSelected onEmojiSelected,
|
||||
LayerLink link,
|
||||
) {
|
||||
// Generate other skintone options
|
||||
final skinTonesEmoji = SkinTone.values
|
||||
.map((skinTone) => _utils.applySkinTone(emoji, skinTone))
|
||||
.toList();
|
||||
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
final emojiPickerRenderbox = context.findRenderObject() as RenderBox;
|
||||
final emojiBoxSize = config.emojiViewConfig.getEmojiBoxSize(
|
||||
emojiPickerRenderbox.size.width,
|
||||
);
|
||||
final left = _calculateLeftOffset(
|
||||
emojiBoxSize,
|
||||
emojiBoxPosition,
|
||||
screenWidth,
|
||||
);
|
||||
final top = _calculateTopOffset(emojiBoxSize);
|
||||
|
||||
_overlay = OverlayEntry(
|
||||
builder: (context) => Positioned(
|
||||
top: 0,
|
||||
left: 0,
|
||||
child: CompositedTransformFollower(
|
||||
offset: Offset(left, top),
|
||||
link: link,
|
||||
showWhenUnlinked: false,
|
||||
child: TapRegion(
|
||||
onTapOutside: (_) => closeSkinToneOverlay(),
|
||||
child: Material(
|
||||
elevation: 4.0,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
||||
color: config.skinToneConfig.dialogBackgroundColor,
|
||||
child: Row(
|
||||
children: [
|
||||
// The first cell is always the neutral (no-tone) glyph so
|
||||
// it doubles as the "reset" option: selecting it clears any
|
||||
// remembered skin tone. When [emoji] carries a remembered
|
||||
// tone this strips it; otherwise it is already neutral.
|
||||
EmojiCell.fromConfig(
|
||||
emoji: _utils.removeSkinTone(emoji),
|
||||
emojiSize: emojiSize,
|
||||
emojiBoxSize: emojiBoxSize,
|
||||
categoryEmoji: categoryEmoji,
|
||||
onEmojiSelected: onEmojiSelected,
|
||||
config: config,
|
||||
),
|
||||
...List.generate(
|
||||
SkinTone.values.length,
|
||||
(index) => EmojiCell.fromConfig(
|
||||
emoji: skinTonesEmoji[index],
|
||||
emojiSize: emojiSize,
|
||||
emojiBoxSize: emojiBoxSize,
|
||||
categoryEmoji: categoryEmoji,
|
||||
onEmojiSelected: onEmojiSelected,
|
||||
config: config,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (_overlay != null) {
|
||||
Overlay.of(context).insert(_overlay!);
|
||||
} else {
|
||||
throw Exception('Nullable skin tone overlay insert attempt');
|
||||
}
|
||||
}
|
||||
|
||||
double _calculateTopOffset(double emojiBoxSize) {
|
||||
final verticalPaddingOverlay = 8.0;
|
||||
final top = -emojiBoxSize - verticalPaddingOverlay;
|
||||
return top;
|
||||
}
|
||||
|
||||
double _calculateLeftOffset(
|
||||
double emojiBoxSize,
|
||||
Offset emojiBoxPosition,
|
||||
double screenWidth,
|
||||
) {
|
||||
var left = -2.5 * emojiBoxSize;
|
||||
|
||||
if (emojiBoxPosition.dx - 1 * emojiBoxSize < 0) {
|
||||
left += 2.5 * emojiBoxSize;
|
||||
} else if (emojiBoxPosition.dx - 2 * emojiBoxSize < 0) {
|
||||
left += 1.5 * emojiBoxSize;
|
||||
} else if (emojiBoxPosition.dx - 3 * emojiBoxSize < 0) {
|
||||
left += 0.5 * emojiBoxSize;
|
||||
} else if (emojiBoxPosition.dx + 2 * emojiBoxSize > screenWidth) {
|
||||
left -= 2.5 * emojiBoxSize;
|
||||
} else if (emojiBoxPosition.dx + 3 * emojiBoxSize > screenWidth) {
|
||||
left -= 1.5 * emojiBoxSize;
|
||||
} else if (emojiBoxPosition.dx + 4 * emojiBoxSize > screenWidth) {
|
||||
left -= 0.5 * emojiBoxSize;
|
||||
}
|
||||
return left;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
closeSkinToneOverlay();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Decoration that can be used to render a triangle in the bottom-right
|
||||
/// corner of a container
|
||||
class TriangleDecoration extends Decoration {
|
||||
/// Constructor
|
||||
const TriangleDecoration({required this.color, required this.size}) : super();
|
||||
|
||||
/// Color of the triangle
|
||||
final Color color;
|
||||
|
||||
/// Width and height of the triangle
|
||||
final double size;
|
||||
|
||||
@override
|
||||
BoxPainter createBoxPainter([VoidCallback? onChanged]) {
|
||||
return _TriangleShapePainter(color, size);
|
||||
}
|
||||
}
|
||||
|
||||
class _TriangleShapePainter extends BoxPainter {
|
||||
/// Constructor
|
||||
/// Expects color that the triangle will be filled with and
|
||||
/// size of the triangle
|
||||
_TriangleShapePainter(Color color, double size) {
|
||||
_painter = Paint()
|
||||
..color = color
|
||||
..style = PaintingStyle.fill;
|
||||
_size = size;
|
||||
}
|
||||
|
||||
late final Paint _painter;
|
||||
late final double _size;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
|
||||
// per documentation, the size should be always not null here, no need
|
||||
// for null checks
|
||||
final s = configuration.size!;
|
||||
var path = Path()
|
||||
..moveTo(s.width + offset.dx, s.height - _size + offset.dy)
|
||||
..lineTo(s.width - _size + offset.dx, s.height + offset.dy)
|
||||
..lineTo(s.width + offset.dx, s.height + offset.dy)
|
||||
..lineTo(s.width + offset.dx, s.height - _size + offset.dy)
|
||||
..close();
|
||||
|
||||
canvas.drawPath(path, _painter);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
/// View order config
|
||||
class ViewOrderConfig {
|
||||
/// Constructor
|
||||
const ViewOrderConfig({
|
||||
this.top = EmojiPickerItem.categoryBar,
|
||||
this.middle = EmojiPickerItem.emojiView,
|
||||
this.bottom = EmojiPickerItem.searchBar,
|
||||
}) : assert(
|
||||
!identical(top, middle) &&
|
||||
!identical(top, bottom) &&
|
||||
!identical(middle, bottom),
|
||||
);
|
||||
|
||||
/// First item
|
||||
final EmojiPickerItem top;
|
||||
|
||||
/// Middle item
|
||||
final EmojiPickerItem middle;
|
||||
|
||||
/// Last item
|
||||
final EmojiPickerItem bottom;
|
||||
|
||||
@override
|
||||
bool operator ==(other) {
|
||||
return (other is ViewOrderConfig) &&
|
||||
other.top == top &&
|
||||
other.middle == middle &&
|
||||
other.bottom == bottom;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => top.hashCode ^ middle.hashCode ^ bottom.hashCode;
|
||||
}
|
||||
|
||||
/// Widgets shown in `EmojiPicker` view
|
||||
enum EmojiPickerItem {
|
||||
/// The tab bar to choose between different emoji categories
|
||||
categoryBar,
|
||||
|
||||
/// The area that shows emojis
|
||||
emojiView,
|
||||
|
||||
/// The search bar to search emojis
|
||||
searchBar,
|
||||
}
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Backspace Button Widget
|
||||
class BackspaceButton extends StatefulWidget {
|
||||
/// Constructor
|
||||
const BackspaceButton(
|
||||
this.config,
|
||||
this.onBackspacePressed,
|
||||
this.onBackspaceLongPressed,
|
||||
this.iconColor, {
|
||||
super.key,
|
||||
});
|
||||
|
||||
/// Config
|
||||
final Config config;
|
||||
|
||||
/// Backspace callback
|
||||
final VoidCallback? onBackspacePressed;
|
||||
|
||||
/// Backspace long press callback
|
||||
final VoidCallback? onBackspaceLongPressed;
|
||||
|
||||
/// Backspace Icon color
|
||||
final Color iconColor;
|
||||
|
||||
@override
|
||||
State<BackspaceButton> createState() => _BackspaceButtonState();
|
||||
}
|
||||
|
||||
class _BackspaceButtonState extends State<BackspaceButton> {
|
||||
Timer? _onBackspacePressedCallbackTimer;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
type: MaterialType.transparency,
|
||||
child: GestureDetector(
|
||||
onLongPressStart: (_) => _startOnBackspacePressedCallback(),
|
||||
onLongPressEnd: (_) => _stopOnBackspacePressedCallback(),
|
||||
child: IconButton(
|
||||
padding: const EdgeInsets.only(bottom: 2),
|
||||
icon:
|
||||
widget.config.customBackspaceIcon ??
|
||||
Icon(Icons.backspace, color: widget.iconColor),
|
||||
onPressed: () {
|
||||
widget.onBackspacePressed?.call();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_onBackspacePressedCallbackTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// Start the callback for long-pressing the backspace button.
|
||||
void _startOnBackspacePressedCallback() {
|
||||
// Initial callback interval for short presses
|
||||
var callbackInterval = const Duration(milliseconds: 75);
|
||||
var millisecondsSincePressed = 0;
|
||||
|
||||
// Callback function executed on each timer tick
|
||||
void _callback(Timer timer) {
|
||||
// Accumulate elapsed time since the last tick
|
||||
millisecondsSincePressed += callbackInterval.inMilliseconds;
|
||||
|
||||
// If the long-press duration exceeds 3 seconds
|
||||
if (millisecondsSincePressed > 3000 &&
|
||||
callbackInterval == const Duration(milliseconds: 75)) {
|
||||
// Switch to a longer callback interval for word-by-word deletion
|
||||
callbackInterval = const Duration(milliseconds: 300);
|
||||
|
||||
// Cancel the existing timer and start a new one with the updated
|
||||
// interval
|
||||
_onBackspacePressedCallbackTimer?.cancel();
|
||||
_onBackspacePressedCallbackTimer = Timer.periodic(
|
||||
callbackInterval,
|
||||
_callback,
|
||||
);
|
||||
|
||||
// Reset the elapsed time for the new interval
|
||||
millisecondsSincePressed = 0;
|
||||
}
|
||||
|
||||
// Trigger the appropriate callback based on the interval
|
||||
if (callbackInterval == const Duration(milliseconds: 75)) {
|
||||
widget.onBackspacePressed?.call(); // Short-press callback
|
||||
} else {
|
||||
widget.onBackspaceLongPressed?.call(); // Long-press callback
|
||||
}
|
||||
}
|
||||
|
||||
// Start the initial timer with the short-press interval
|
||||
_onBackspacePressedCallbackTimer = Timer.periodic(
|
||||
callbackInterval,
|
||||
_callback,
|
||||
);
|
||||
}
|
||||
|
||||
/// Stop the callback for long-pressing the backspace button.
|
||||
void _stopOnBackspacePressedCallback() {
|
||||
// Cancel the active timer
|
||||
_onBackspacePressedCallbackTimer?.cancel();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,164 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// A widget that represents an individual clickable emoji cell.
|
||||
/// Can have a long pressed listener [onSkinToneDialogRequested] that
|
||||
/// provides necessary data to show a skin tone popup.
|
||||
class EmojiCell extends StatelessWidget {
|
||||
/// Constructor for manually setting all properties
|
||||
const EmojiCell({
|
||||
super.key,
|
||||
required this.emoji,
|
||||
required this.emojiSize,
|
||||
required this.emojiBoxSize,
|
||||
this.categoryEmoji,
|
||||
required this.buttonMode,
|
||||
required this.enableSkinTones,
|
||||
required this.textStyle,
|
||||
required this.skinToneIndicatorColor,
|
||||
this.onSkinToneDialogRequested,
|
||||
required this.onEmojiSelected,
|
||||
});
|
||||
|
||||
/// Constructor that can retrieve as much information as possible from
|
||||
/// [Config]
|
||||
EmojiCell.fromConfig({
|
||||
super.key,
|
||||
required this.emoji,
|
||||
required this.emojiSize,
|
||||
required this.emojiBoxSize,
|
||||
this.categoryEmoji,
|
||||
required this.onEmojiSelected,
|
||||
this.onSkinToneDialogRequested,
|
||||
required Config config,
|
||||
}) : buttonMode = config.emojiViewConfig.buttonMode,
|
||||
enableSkinTones = config.skinToneConfig.enabled,
|
||||
textStyle = config.emojiTextStyle,
|
||||
skinToneIndicatorColor = config.skinToneConfig.indicatorColor;
|
||||
|
||||
/// Emoji to display as the cell content
|
||||
final Emoji emoji;
|
||||
|
||||
/// Font size for the emoji
|
||||
final double emojiSize;
|
||||
|
||||
/// Hitbox of emoji cell
|
||||
final double emojiBoxSize;
|
||||
|
||||
/// Optinonal category that will be passed through to callbacks
|
||||
final CategoryEmoji? categoryEmoji;
|
||||
|
||||
/// Visual tap feedback, see [ButtonMode] for options
|
||||
final ButtonMode buttonMode;
|
||||
|
||||
/// Whether to show skin popup indicator if emoji supports skin colors
|
||||
final bool enableSkinTones;
|
||||
|
||||
/// Custom text style to use on emoji
|
||||
final TextStyle? textStyle;
|
||||
|
||||
/// Color for skin color indicator triangle
|
||||
final Color skinToneIndicatorColor;
|
||||
|
||||
/// Callback triggered on long press. Will be called regardless
|
||||
/// whether [enableSkinTones] is set or not and for any emoji to
|
||||
/// give a way for the caller to dismiss any existing overlays.
|
||||
final OnSkinToneDialogRequested? onSkinToneDialogRequested;
|
||||
|
||||
/// Callback for a single tap on the cell.
|
||||
final OnEmojiSelected onEmojiSelected;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
onPressed() {
|
||||
onEmojiSelected(categoryEmoji?.category, emoji);
|
||||
}
|
||||
|
||||
onLongPressed() {
|
||||
final renderBox = context.findRenderObject() as RenderBox;
|
||||
final emojiBoxPosition = renderBox.localToGlobal(Offset.zero);
|
||||
onSkinToneDialogRequested?.call(
|
||||
emojiBoxPosition,
|
||||
emoji,
|
||||
emojiSize,
|
||||
categoryEmoji,
|
||||
);
|
||||
}
|
||||
|
||||
return SizedBox(
|
||||
width: emojiBoxSize,
|
||||
height: emojiBoxSize,
|
||||
child: _buildButtonWidget(
|
||||
onPressed: onPressed,
|
||||
onLongPressed: onLongPressed,
|
||||
child: FittedBox(fit: BoxFit.scaleDown, child: _buildEmoji()),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Build different Button based on ButtonMode
|
||||
Widget _buildButtonWidget({
|
||||
required VoidCallback onPressed,
|
||||
VoidCallback? onLongPressed,
|
||||
required Widget child,
|
||||
}) {
|
||||
if (buttonMode == ButtonMode.MATERIAL) {
|
||||
return MaterialButton(
|
||||
onPressed: onPressed,
|
||||
onLongPress: onLongPressed,
|
||||
elevation: 0,
|
||||
highlightElevation: 0,
|
||||
padding: EdgeInsets.zero,
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
if (buttonMode == ButtonMode.CUPERTINO) {
|
||||
return GestureDetector(
|
||||
onLongPress: onLongPressed,
|
||||
child: CupertinoButton(
|
||||
onPressed: onPressed,
|
||||
padding: EdgeInsets.zero,
|
||||
alignment: Alignment.center,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
}
|
||||
return GestureDetector(
|
||||
onLongPress: onLongPressed,
|
||||
onTap: onPressed,
|
||||
child: Center(child: child),
|
||||
);
|
||||
}
|
||||
|
||||
/// Build and display Emoji centered of its parent
|
||||
Widget _buildEmoji() {
|
||||
final emojiText = Text(
|
||||
emoji.emoji,
|
||||
textScaler: const TextScaler.linear(1.0),
|
||||
style: _getEmojiTextStyle(),
|
||||
);
|
||||
|
||||
return emoji.hasSkinTone &&
|
||||
enableSkinTones &&
|
||||
onSkinToneDialogRequested != null
|
||||
? Container(
|
||||
decoration: TriangleDecoration(
|
||||
color: skinToneIndicatorColor,
|
||||
size: 8.0,
|
||||
),
|
||||
child: emojiText,
|
||||
)
|
||||
: emojiText;
|
||||
}
|
||||
|
||||
TextStyle _getEmojiTextStyle() {
|
||||
final defaultStyle = DefaultEmojiTextStyle.copyWith(
|
||||
fontSize: emojiSize,
|
||||
inherit: true,
|
||||
);
|
||||
// textStyle properties have priority over defaultStyle
|
||||
return textStyle == null ? defaultStyle : defaultStyle.merge(textStyle);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Search Button Widget
|
||||
class SearchButton extends StatelessWidget {
|
||||
/// Constructor
|
||||
const SearchButton(
|
||||
this.config,
|
||||
this.showSearchView,
|
||||
this.buttonIconColor, {
|
||||
super.key,
|
||||
});
|
||||
|
||||
/// Config
|
||||
final Config config;
|
||||
|
||||
/// Show search view callback
|
||||
final VoidCallback showSearchView;
|
||||
|
||||
/// Button icon color
|
||||
final Color buttonIconColor;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return IconButton(
|
||||
onPressed: showSearchView,
|
||||
icon:
|
||||
config.customSearchIcon ?? Icon(Icons.search, color: buttonIconColor),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
name: emoji_picker_flutter
|
||||
description: A Flutter package that provides an Emoji picker widget with 1500+ emojis in 8 categories.
|
||||
version: 4.5.3
|
||||
homepage: https://github.com/Fintasys/emoji_picker_flutter
|
||||
|
||||
screenshots:
|
||||
- description: 'Default emoji picker on Android'
|
||||
path: screenshot/example_custom_font_android.png
|
||||
- description: 'WhatsApp-style emoji view'
|
||||
path: screenshot/example_whatsapp_emoji_view.png
|
||||
- description: 'WhatsApp-style search view'
|
||||
path: screenshot/example_whatsapp_search_view.png
|
||||
|
||||
environment:
|
||||
sdk: ">=3.11.5 <4.0.0"
|
||||
flutter: ">=3.41.8"
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter_web_plugins:
|
||||
sdk: flutter
|
||||
plugin_platform_interface: ^2.1.8
|
||||
shared_preferences: ^2.3.3
|
||||
web: ^1.1.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter_lints: ^6.0.0
|
||||
test: ^1.25.7
|
||||
|
||||
flutter:
|
||||
plugin:
|
||||
platforms:
|
||||
android:
|
||||
package: com.fintasys.emoji_picker_flutter
|
||||
pluginClass: EmojiPickerFlutterPlugin
|
||||
ios:
|
||||
pluginClass: EmojiPickerFlutterPlugin
|
||||
macos:
|
||||
pluginClass: EmojiPickerFlutterPlugin
|
||||
windows:
|
||||
pluginClass: EmojiPickerFlutterPluginCApi
|
||||
linux:
|
||||
pluginClass: EmojiPickerFlutterPlugin
|
||||
web:
|
||||
pluginClass: EmojiPickerFlutterPluginWeb
|
||||
fileName: emoji_picker_flutter_web.dart
|
||||
674
libsignal_protocol_dart/LICENSE
Normal file
674
libsignal_protocol_dart/LICENSE
Normal file
|
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
52
libsignal_protocol_dart/lib/libsignal_protocol_dart.dart
Normal file
52
libsignal_protocol_dart/lib/libsignal_protocol_dart.dart
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
export 'src/decryption_callback.dart';
|
||||
export 'src/duplicate_message_exception.dart';
|
||||
export 'src/ecc/curve.dart';
|
||||
export 'src/ecc/djb_ec_private_key.dart';
|
||||
export 'src/ecc/djb_ec_public_key.dart';
|
||||
export 'src/ecc/ec_key_pair.dart';
|
||||
export 'src/ecc/ec_private_key.dart';
|
||||
export 'src/ecc/ec_public_key.dart';
|
||||
export 'src/fingerprint/displayable_fingerprint.dart';
|
||||
export 'src/fingerprint/fingerprint.dart';
|
||||
export 'src/fingerprint/numeric_fingerprint_generator.dart';
|
||||
export 'src/fingerprint/scannable_fingerprint.dart';
|
||||
export 'src/groups/group_cipher.dart';
|
||||
export 'src/groups/group_session_builder.dart';
|
||||
export 'src/groups/sender_key_name.dart';
|
||||
export 'src/groups/state/in_memory_sender_key_store.dart';
|
||||
export 'src/groups/state/sender_key_record.dart';
|
||||
export 'src/groups/state/sender_key_store.dart';
|
||||
export 'src/identity_key.dart';
|
||||
export 'src/identity_key_pair.dart';
|
||||
export 'src/invalid_key_exception.dart';
|
||||
export 'src/invalid_key_id_exception.dart';
|
||||
export 'src/legacy_message_exception.dart';
|
||||
export 'src/no_session_exception.dart';
|
||||
export 'src/protocol/ciphertext_message.dart';
|
||||
export 'src/protocol/pre_key_signal_message.dart';
|
||||
export 'src/protocol/sender_key_distribution_message_wrapper.dart';
|
||||
export 'src/protocol/sender_key_message.dart';
|
||||
export 'src/protocol/signal_message.dart';
|
||||
export 'src/provisioning_cipher.dart';
|
||||
export 'src/session_builder.dart';
|
||||
export 'src/session_cipher.dart';
|
||||
export 'src/signal_protocol_address.dart';
|
||||
export 'src/state/identity_key_store.dart';
|
||||
export 'src/state/impl/in_memory_identity_key_store.dart';
|
||||
export 'src/state/impl/in_memory_pre_key_store.dart';
|
||||
export 'src/state/impl/in_memory_session_store.dart';
|
||||
export 'src/state/impl/in_memory_signal_protocol_store.dart';
|
||||
export 'src/state/impl/in_memory_signed_pre_key_store.dart';
|
||||
export 'src/state/pre_key_bundle.dart';
|
||||
export 'src/state/pre_key_record.dart';
|
||||
export 'src/state/pre_key_store.dart';
|
||||
export 'src/state/session_record.dart';
|
||||
export 'src/state/session_state.dart';
|
||||
export 'src/state/session_store.dart';
|
||||
export 'src/state/signal_protocol_store.dart';
|
||||
export 'src/state/signed_pre_key_record.dart';
|
||||
export 'src/state/signed_pre_key_store.dart';
|
||||
export 'src/untrusted_identity_exception.dart';
|
||||
export 'src/util/byte_util.dart';
|
||||
export 'src/util/key_helper.dart';
|
||||
export 'src/util/medium.dart';
|
||||
40
libsignal_protocol_dart/lib/src/cbc.dart
Normal file
40
libsignal_protocol_dart/lib/src/cbc.dart
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:pointycastle/export.dart';
|
||||
|
||||
Uint8List aesCbcEncrypt(Uint8List key, Uint8List iv, Uint8List plaintext) {
|
||||
final paddedPlaintext = pad(plaintext, 16);
|
||||
final cbc = CBCBlockCipher(AESEngine())
|
||||
..init(true, ParametersWithIV(KeyParameter(key), iv)); // true=encrypt
|
||||
|
||||
final cipherText = Uint8List(paddedPlaintext.length); // allocate space
|
||||
var offset = 0;
|
||||
while (offset < paddedPlaintext.length) {
|
||||
offset += cbc.processBlock(paddedPlaintext, offset, cipherText, offset);
|
||||
}
|
||||
assert(offset == paddedPlaintext.length);
|
||||
return cipherText;
|
||||
}
|
||||
|
||||
Uint8List aesCbcDecrypt(Uint8List key, Uint8List iv, Uint8List cipherText) {
|
||||
final cbc = CBCBlockCipher(AESEngine())
|
||||
..init(false, ParametersWithIV(KeyParameter(key), iv)); // false=decrypt
|
||||
|
||||
final paddedPlainText = Uint8List(cipherText.length); // allocate space
|
||||
var offset = 0;
|
||||
while (offset < cipherText.length) {
|
||||
offset += cbc.processBlock(cipherText, offset, paddedPlainText, offset);
|
||||
}
|
||||
assert(offset == cipherText.length);
|
||||
return unpad(paddedPlainText);
|
||||
}
|
||||
|
||||
Uint8List pad(Uint8List bytes, int blockSize) {
|
||||
final padLength = blockSize - (bytes.length % blockSize);
|
||||
final padded = Uint8List(bytes.length + padLength)..setAll(0, bytes);
|
||||
PKCS7Padding().addPadding(padded, bytes.length);
|
||||
return padded;
|
||||
}
|
||||
|
||||
Uint8List unpad(Uint8List padded) =>
|
||||
padded.sublist(0, padded.length - PKCS7Padding().padCount(padded));
|
||||
3
libsignal_protocol_dart/lib/src/decryption_callback.dart
Normal file
3
libsignal_protocol_dart/lib/src/decryption_callback.dart
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
typedef DecryptionCallback = void Function(Uint8List plaintext);
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:convert/convert.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import '../util/byte_util.dart';
|
||||
|
||||
import 'device_consistency_commitment.dart';
|
||||
import 'device_consistency_signature.dart';
|
||||
|
||||
class DeviceConsistencyCodeGenerator {
|
||||
static const int codeVersion = 0;
|
||||
|
||||
static String generateFor(DeviceConsistencyCommitment commitment,
|
||||
List<DeviceConsistencySignature> signatures) {
|
||||
final sortedSignatures = <DeviceConsistencySignature>[...signatures]
|
||||
..sort(compareSignature);
|
||||
|
||||
final output = AccumulatorSink<Digest>();
|
||||
final input = sha512.startChunkedConversion(output)
|
||||
..add(ByteUtil.shortToByteArray(codeVersion))
|
||||
..add(commitment.serialized);
|
||||
|
||||
for (final signature in sortedSignatures) {
|
||||
input.add(signature.vrfOutput);
|
||||
}
|
||||
input.close();
|
||||
final hash = output.events.single.bytes;
|
||||
final digits = getEncodedChunk(Uint8List.fromList(hash), 0) +
|
||||
getEncodedChunk(Uint8List.fromList(hash), 5);
|
||||
return digits.substring(0, 6);
|
||||
}
|
||||
|
||||
static String getEncodedChunk(Uint8List hash, int offset) {
|
||||
final chunk = ByteUtil.byteArray5ToLong(hash, offset).remainder(100000);
|
||||
return chunk.toString().padLeft(5, '0');
|
||||
}
|
||||
}
|
||||
|
||||
int compareSignature(
|
||||
DeviceConsistencySignature a, DeviceConsistencySignature b) =>
|
||||
ByteUtil.compare(a.vrfOutput, b.vrfOutput);
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:convert/convert.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
|
||||
import '../identity_key.dart';
|
||||
import '../util/byte_util.dart';
|
||||
|
||||
class DeviceConsistencyCommitment {
|
||||
DeviceConsistencyCommitment(int generation, List<IdentityKey> identityKeys) {
|
||||
final sortedIdentityKeys = <IdentityKey>[...identityKeys]..sort((a, b) =>
|
||||
ByteUtil.compare(a.publicKey.serialize(), b.publicKey.serialize()));
|
||||
|
||||
final output = AccumulatorSink<Digest>();
|
||||
final input = sha512.startChunkedConversion(output)
|
||||
..add(utf8.encode(version))
|
||||
..add(ByteUtil.intToByteArray(generation));
|
||||
|
||||
for (final commitment in sortedIdentityKeys) {
|
||||
input.add(commitment.publicKey.serialize());
|
||||
}
|
||||
input.close();
|
||||
|
||||
_generation = generation;
|
||||
_serialized = Uint8List.fromList(output.events.single.bytes);
|
||||
}
|
||||
|
||||
static const String version = 'DeviceConsistencyCommitment_V0';
|
||||
|
||||
late int _generation;
|
||||
late Uint8List _serialized;
|
||||
|
||||
Uint8List get serialized => _serialized;
|
||||
|
||||
int get generation => _generation;
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
class DeviceConsistencySignature {
|
||||
DeviceConsistencySignature(this._signature, this._vrfOutput);
|
||||
|
||||
final Uint8List _signature;
|
||||
final Uint8List _vrfOutput;
|
||||
|
||||
Uint8List get vrfOutput => _vrfOutput;
|
||||
|
||||
Uint8List get signature => _signature;
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
class DuplicateMessageException implements Exception {
|
||||
DuplicateMessageException(this.detailMessage);
|
||||
final String detailMessage;
|
||||
|
||||
@override
|
||||
String toString() => 'DuplicateMessageException - $detailMessage';
|
||||
}
|
||||
187
libsignal_protocol_dart/lib/src/ecc/curve.dart
Normal file
187
libsignal_protocol_dart/lib/src/ecc/curve.dart
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:x25519/x25519.dart' as x25519;
|
||||
|
||||
import '../invalid_key_exception.dart';
|
||||
import '../util/key_helper.dart';
|
||||
import 'djb_ec_private_key.dart';
|
||||
import 'djb_ec_public_key.dart';
|
||||
import 'ec_key_pair.dart';
|
||||
import 'ec_private_key.dart';
|
||||
import 'ec_public_key.dart';
|
||||
import 'ed25519.dart';
|
||||
|
||||
typedef KeyPairGenerator = GeneratedKeyPair Function();
|
||||
typedef AgreementCalculator = Uint8List Function(Uint8List, Uint8List);
|
||||
|
||||
class GeneratedKeyPair {
|
||||
GeneratedKeyPair(this.private, this.public);
|
||||
|
||||
final Uint8List private;
|
||||
final Uint8List public;
|
||||
}
|
||||
|
||||
class Curve {
|
||||
static const int djbType = 0x05;
|
||||
|
||||
static KeyPairGenerator? keyPairGenerator;
|
||||
static AgreementCalculator? agreementCalculator;
|
||||
|
||||
static ECKeyPair generateKeyPair() {
|
||||
final x25519.KeyPair keyPair;
|
||||
final generator = keyPairGenerator;
|
||||
if (generator != null) {
|
||||
final kp = generator();
|
||||
keyPair = x25519.KeyPair(privateKey: kp.private, publicKey: kp.public);
|
||||
} else {
|
||||
keyPair = x25519.generateKeyPair();
|
||||
}
|
||||
|
||||
return ECKeyPair(DjbECPublicKey(Uint8List.fromList(keyPair.publicKey)),
|
||||
DjbECPrivateKey(Uint8List.fromList(keyPair.privateKey)));
|
||||
}
|
||||
|
||||
static ECKeyPair generateKeyPairFromPrivate(List<int> private) {
|
||||
if (private.length != 32) {
|
||||
throw InvalidKeyException(
|
||||
'Invalid private key length: ${private.length}');
|
||||
}
|
||||
final public = List<int>.filled(32, 0);
|
||||
|
||||
private[0] &= 248;
|
||||
private[31] &= 127;
|
||||
private[31] |= 64;
|
||||
|
||||
x25519.ScalarBaseMult(public, private);
|
||||
|
||||
return ECKeyPair(DjbECPublicKey(Uint8List.fromList(public)),
|
||||
DjbECPrivateKey(Uint8List.fromList(private)));
|
||||
}
|
||||
|
||||
static ECPublicKey decodePointList(List<int> bytes, int offset) =>
|
||||
decodePoint(Uint8List.fromList(bytes), offset);
|
||||
|
||||
static ECPublicKey decodePoint(Uint8List bytes, int offset) {
|
||||
if (bytes.length - offset < 1) {
|
||||
throw InvalidKeyException('No key type identifier');
|
||||
}
|
||||
|
||||
final type = bytes[offset] & 0xFF;
|
||||
|
||||
switch (type) {
|
||||
case Curve.djbType:
|
||||
if (bytes.length - offset < 33) {
|
||||
throw InvalidKeyException('Bad key length: ${bytes.length}');
|
||||
}
|
||||
|
||||
final keyBytes = Uint8List(32);
|
||||
arraycopy(bytes, offset + 1, keyBytes, 0, keyBytes.length);
|
||||
return DjbECPublicKey(keyBytes);
|
||||
default:
|
||||
throw InvalidKeyException('Bad key type: $type');
|
||||
}
|
||||
}
|
||||
|
||||
static void arraycopy(
|
||||
List<int> src, int srcPos, List<int> dest, int destPos, int length) {
|
||||
dest.setRange(destPos, length + destPos, src, srcPos);
|
||||
}
|
||||
|
||||
static ECPrivateKey decodePrivatePoint(Uint8List bytes) =>
|
||||
DjbECPrivateKey(bytes);
|
||||
|
||||
static Uint8List calculateAgreement(
|
||||
ECPublicKey? publicKey, ECPrivateKey? privateKey) {
|
||||
if (publicKey == null) {
|
||||
throw Exception('publicKey value is null');
|
||||
}
|
||||
|
||||
if (privateKey == null) {
|
||||
throw Exception('privateKey value is null');
|
||||
}
|
||||
if (publicKey.getType() != privateKey.getType()) {
|
||||
throw Exception('Public and private keys must be of the same type!');
|
||||
}
|
||||
|
||||
if (publicKey.getType() == djbType) {
|
||||
final calculator = agreementCalculator;
|
||||
if (calculator != null) {
|
||||
return calculator(
|
||||
(privateKey as DjbECPrivateKey).privateKey,
|
||||
(publicKey as DjbECPublicKey).publicKey,
|
||||
);
|
||||
}
|
||||
|
||||
final secretKey = x25519.X25519(
|
||||
List<int>.from((privateKey as DjbECPrivateKey).privateKey),
|
||||
List<int>.from((publicKey as DjbECPublicKey).publicKey),
|
||||
);
|
||||
return secretKey;
|
||||
} else {
|
||||
throw Exception('Unknown type: ${publicKey.getType()}');
|
||||
}
|
||||
}
|
||||
|
||||
static bool verifySignature(
|
||||
ECPublicKey? signingKey, Uint8List? message, Uint8List? signature) {
|
||||
if (signingKey == null || message == null || signature == null) {
|
||||
throw InvalidKeyException('Values must not be null');
|
||||
}
|
||||
|
||||
if (signingKey.getType() == djbType) {
|
||||
if (signature.length != 64) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final publicKey = (signingKey as DjbECPublicKey).publicKey;
|
||||
return verifySig(publicKey, message, signature);
|
||||
} else {
|
||||
throw InvalidKeyException(
|
||||
'Unknown Signing Key type${signingKey.getType()}');
|
||||
}
|
||||
}
|
||||
|
||||
static Uint8List calculateSignature(
|
||||
ECPrivateKey? signingKey, Uint8List? message) {
|
||||
if (signingKey == null || message == null) {
|
||||
throw Exception('Values must not be null');
|
||||
}
|
||||
|
||||
if (signingKey.getType() == djbType) {
|
||||
final privateKey = signingKey.serialize();
|
||||
final random = generateRandomBytes();
|
||||
|
||||
return sign(privateKey, message, random);
|
||||
} else {
|
||||
throw Exception('Unknown Signing Key type${signingKey.getType()}');
|
||||
}
|
||||
}
|
||||
|
||||
static Uint8List calculateVrfSignature(
|
||||
ECPrivateKey? signingKey, Uint8List? message) {
|
||||
if (signingKey == null || message == null) {
|
||||
throw Exception('Values must not be null');
|
||||
}
|
||||
|
||||
if (signingKey.getType() == djbType) {
|
||||
// TODO
|
||||
} else {
|
||||
throw Exception('Unknown Signing Key type${signingKey.getType()}');
|
||||
}
|
||||
return Uint8List(0);
|
||||
}
|
||||
|
||||
static Uint8List verifyVrfSignature(
|
||||
ECPublicKey? signingKey, Uint8List? message, Uint8List? signature) {
|
||||
if (signingKey == null || message == null || signature == null) {
|
||||
throw Exception('Values must not be null');
|
||||
}
|
||||
|
||||
if (signingKey.getType() == djbType) {
|
||||
// TODO
|
||||
} else {
|
||||
throw Exception('Unknown Signing Key type${signingKey.getType()}');
|
||||
}
|
||||
return Uint8List(0);
|
||||
}
|
||||
}
|
||||
18
libsignal_protocol_dart/lib/src/ecc/djb_ec_private_key.dart
Normal file
18
libsignal_protocol_dart/lib/src/ecc/djb_ec_private_key.dart
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'curve.dart';
|
||||
import 'ec_private_key.dart';
|
||||
|
||||
class DjbECPrivateKey extends ECPrivateKey {
|
||||
DjbECPrivateKey(this._privateKey);
|
||||
|
||||
final Uint8List _privateKey;
|
||||
|
||||
@override
|
||||
int getType() => Curve.djbType;
|
||||
|
||||
@override
|
||||
Uint8List serialize() => privateKey;
|
||||
|
||||
Uint8List get privateKey => _privateKey;
|
||||
}
|
||||
44
libsignal_protocol_dart/lib/src/ecc/djb_ec_public_key.dart
Normal file
44
libsignal_protocol_dart/lib/src/ecc/djb_ec_public_key.dart
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../eq.dart';
|
||||
|
||||
import 'curve.dart';
|
||||
import 'ec_public_key.dart';
|
||||
|
||||
@immutable
|
||||
class DjbECPublicKey extends ECPublicKey {
|
||||
DjbECPublicKey(this._publicKey);
|
||||
|
||||
final Uint8List _publicKey;
|
||||
|
||||
@override
|
||||
int getType() => Curve.djbType;
|
||||
|
||||
@override
|
||||
Uint8List serialize() => Uint8List.fromList([Curve.djbType] + _publicKey);
|
||||
|
||||
Uint8List get publicKey => _publicKey;
|
||||
|
||||
@override
|
||||
int compareTo(ECPublicKey another) => decodeBigInt(publicKey)
|
||||
.compareTo(decodeBigInt((another as DjbECPublicKey).publicKey));
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (other is! DjbECPublicKey) return false;
|
||||
return eq(_publicKey, other._publicKey);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => _publicKey.hashCode;
|
||||
|
||||
BigInt decodeBigInt(List<int> bytes) {
|
||||
var result = BigInt.from(0);
|
||||
for (var i = 0; i < bytes.length; i++) {
|
||||
result += BigInt.from(bytes[bytes.length - i - 1]) << (8 * i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
13
libsignal_protocol_dart/lib/src/ecc/ec_key_pair.dart
Normal file
13
libsignal_protocol_dart/lib/src/ecc/ec_key_pair.dart
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import 'ec_private_key.dart';
|
||||
import 'ec_public_key.dart';
|
||||
|
||||
class ECKeyPair {
|
||||
ECKeyPair(this._publicKey, this._privateKey);
|
||||
|
||||
final ECPublicKey _publicKey;
|
||||
final ECPrivateKey _privateKey;
|
||||
|
||||
ECPublicKey get publicKey => _publicKey;
|
||||
|
||||
ECPrivateKey get privateKey => _privateKey;
|
||||
}
|
||||
6
libsignal_protocol_dart/lib/src/ecc/ec_private_key.dart
Normal file
6
libsignal_protocol_dart/lib/src/ecc/ec_private_key.dart
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
abstract class ECPrivateKey {
|
||||
Uint8List serialize();
|
||||
int getType();
|
||||
}
|
||||
8
libsignal_protocol_dart/lib/src/ecc/ec_public_key.dart
Normal file
8
libsignal_protocol_dart/lib/src/ecc/ec_public_key.dart
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
abstract class ECPublicKey implements Comparable<ECPublicKey> {
|
||||
static const int keySize = 33;
|
||||
|
||||
Uint8List serialize();
|
||||
int getType();
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue