Update the example, android example, and few changes

pull/1508/head
Ellet 1 year ago
parent 8e0441e224
commit 4aad60419c
No known key found for this signature in database
GPG Key ID: C488CC70BBCEF0D1
  1. 17
      example/android/app/build.gradle
  2. 30
      example/android/app/src/main/AndroidManifest.xml
  3. 3
      example/android/app/src/main/kotlin/com/example/example/MainActivity.kt
  4. 47
      example/android/build.gradle
  5. 3
      example/android/gradle.properties
  6. 2
      example/android/gradle/wrapper/gradle-wrapper.properties
  7. 47
      example/assets/sample_data.json
  8. 12
      example/lib/pages/home_page.dart
  9. 2
      flutter_quill_test/pubspec.yaml
  10. 4
      lib/src/models/documents/document.dart
  11. 2
      lib/src/utils/color.dart
  12. 6
      lib/src/utils/delta.dart
  13. 2
      lib/src/utils/embeds.dart
  14. 3
      lib/src/utils/extensions/build_context.dart
  15. 2
      lib/src/utils/font.dart
  16. 6
      lib/src/widgets/raw_editor/raw_editor.dart
  17. 2
      lib/src/widgets/text_block.dart
  18. 10
      lib/src/widgets/text_selection.dart

@ -24,16 +24,18 @@ if (flutterVersionName == null) {
android {
namespace "com.example.example"
compileSdkVersion flutter.compileSdkVersion
compileSdk flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
def javaVersion = JavaVersion.VERSION_17
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility javaVersion
targetCompatibility javaVersion
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = javaVersion.toString()
}
sourceSets {
@ -41,11 +43,8 @@ android {
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.example"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion flutter.minSdkVersion
minSdkVersion 24
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
@ -53,8 +52,6 @@ android {
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}

@ -1,23 +1,34 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<!-- The camera and gps features will be used -->
<!-- But it's not required to install the app -->
<uses-feature
android:name="android.hardware.location.gps"
android:required="false" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<application
android:label="example"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
android:icon="@mipmap/ic_launcher"
android:label="example">
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:exported="true"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
@ -25,8 +36,7 @@
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
android:resource="@style/NormalTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

@ -2,5 +2,4 @@ package com.example.example
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
class MainActivity: FlutterActivity()

@ -1,12 +1,14 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {
ext.kotlin_version = '1.7.10'
ext.kotlin_version = '1.9.20'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath 'com.android.tools.build:gradle:8.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
@ -21,6 +23,47 @@ allprojects {
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
// For mode details visit https://gist.github.com/freshtechtips/93fefb39e48c40592bda3931e05fd35c
afterEvaluate {
// check if android block is available
if (it.hasProperty('android')) {
if (it.android.namespace == null) {
def manifest = new XmlSlurper().parse(file(it.android.sourceSets.main.manifest.srcFile))
def packageName = manifest.@package.text()
println("Setting ${packageName} as android namespace in build.gradle from the AndroidManifest.xml")
android.namespace = packageName
}
def javaVersion = JavaVersion.VERSION_17
println("Changes will be applied for the following packages:")
android {
def androidApiVersion = 34
// compileSdkVersion androidApiVersion
compileSdk androidApiVersion
defaultConfig {
targetSdkVersion androidApiVersion
}
compileOptions {
sourceCompatibility javaVersion
targetCompatibility javaVersion
}
tasks.withType(KotlinCompile).configureEach {
buildscript {
ext.kotlin_version = kotlin_version
}
kotlinOptions {
jvmTarget = javaVersion.toString()
}
}
String message = "For package ${android.namespace} by update compileSdkVersion, targetSdkVersion \n to $androidApiVersion and java version to ${javaVersion.toString()}"
println(message)
}
}
}
}
subprojects {
project.evaluationDependsOn(':app')

@ -1,3 +1,6 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false

@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip

@ -45,53 +45,6 @@
},
"insert": "\n"
},
{
"insert": "This "
},
{
"attributes": {
"italic": true,
"background": "transparent"
},
"insert": "library"
},
{
"insert": " supports "
},
{
"attributes": {
"bold": true,
"background": "#ebd6ff"
},
"insert": "mobile"
},
{
"insert": " platform "
},
{
"attributes": {
"underline": true,
"bold": true,
"color": "#e60000"
},
"insert": "only"
},
{
"attributes": {
"color": "rgba(0, 0, 0, 0.847)"
},
"insert": " and "
},
{
"attributes": {
"strike": true,
"color": "black"
},
"insert": "web"
},
{
"insert": " is not supported.\nYou are welcome to use "
},
{
"attributes": {
"link": "https://bulletjournal.us/home/index.html"

@ -149,6 +149,7 @@ class _HomePageState extends State<HomePage> {
tooltip: 'Open document by json delta',
onPressed: () async {
final scaffoldMessenger = ScaffoldMessenger.of(context);
final navigator = Navigator.of(context);
try {
final result = await FilePicker.platform.pickFiles(
dialogTitle: 'Pick json delta',
@ -175,6 +176,8 @@ class _HomePageState extends State<HomePage> {
),
),
);
} finally {
navigator.pop();
}
},
icon: const Icon(Icons.file_copy),
@ -184,6 +187,7 @@ class _HomePageState extends State<HomePage> {
title: const Text('Load sample data'),
onTap: () async {
final scaffoldMessenger = ScaffoldMessenger.of(context);
final navigator = Navigator.of(context);
try {
final jsonString = await rootBundle.loadString(
'assets/sample_data.json',
@ -200,6 +204,8 @@ class _HomePageState extends State<HomePage> {
'Error while loading json delta file: ${e.toString()}',
),
));
} finally {
navigator.pop();
}
},
),
@ -207,6 +213,7 @@ class _HomePageState extends State<HomePage> {
title: const Text('Load sample data with no media'),
onTap: () async {
final scaffoldMessenger = ScaffoldMessenger.of(context);
final navigator = Navigator.of(context);
try {
final jsonString = await rootBundle.loadString(
'assets/sample_data_nomedia.json',
@ -223,6 +230,8 @@ class _HomePageState extends State<HomePage> {
'Error while loading json delta file: ${e.toString()}',
),
));
} finally {
navigator.pop();
}
},
),
@ -230,6 +239,7 @@ class _HomePageState extends State<HomePage> {
title: const Text('Load testing sample data '),
onTap: () async {
final scaffoldMessenger = ScaffoldMessenger.of(context);
final navigator = Navigator.of(context);
try {
final jsonString = await rootBundle.loadString(
'assets/sample_data_testing.json',
@ -246,6 +256,8 @@ class _HomePageState extends State<HomePage> {
'Error while loading json delta file: ${e.toString()}',
),
));
} finally {
navigator.pop();
}
},
),

@ -26,7 +26,7 @@ environment:
dependencies:
flutter:
sdk: flutter
flutter_quill: ^8.2.3
flutter_quill: ^8.2.4
flutter_test:
sdk: flutter

@ -313,11 +313,11 @@ class Document {
try {
_delta = _delta.compose(delta);
} catch (e) {
throw '_delta compose failed';
throw StateError('_delta compose failed');
}
if (_delta != _root.toDelta()) {
throw 'Compose failed';
throw StateError('Compose failed');
}
final change = DocChange(originalDelta, delta, changeSource);
_observer.add(change);

@ -118,7 +118,7 @@ Color stringToColor(String? s, [Color? originalColor]) {
}
if (!s.startsWith('#')) {
throw 'Color code not supported';
throw UnsupportedError('Color code not supported');
}
var hex = s.replaceFirst('#', '');

@ -64,8 +64,10 @@ int getPositionDelta(Delta user, Delta actual) {
final userOperation = userItr.next(length);
final actualOperation = actualItr.next(length);
if (userOperation.length != actualOperation.length) {
throw 'userOp ${userOperation.length} does not match actualOp '
'${actualOperation.length}';
throw ArgumentError(
'userOp ${userOperation.length} does not match actualOp '
'${actualOperation.length}',
);
}
if (userOperation.key == actualOperation.key) {
continue;

@ -15,5 +15,5 @@ OffsetValue<Embed> getEmbedNode(QuillController controller, int offset) {
return OffsetValue(offset, embedNode);
}
return throw 'Embed node not found by offset $offset';
return throw ArgumentError('Embed node not found by offset $offset');
}

@ -2,8 +2,7 @@ import 'package:flutter/widgets.dart' show BuildContext;
import '../../../flutter_quill.dart';
// TODO: The documentation of this file needs to
//be updated as it's quite oudated.
// TODO: The comments of this file might needs to be updated.
/// Public shared extension
extension BuildContextExt on BuildContext {

@ -15,7 +15,7 @@ dynamic getFontSize(dynamic sizeValue) {
assert(sizeValue is String);
final fontSize = double.tryParse(sizeValue);
if (fontSize == null) {
throw 'Invalid size $sizeValue';
throw ArgumentError('Invalid size $sizeValue');
}
return fontSize;
}

@ -1030,7 +1030,9 @@ class QuillRawEditorState extends EditorState
}
VerticalSpacing _getVerticalSpacingForLine(
Line line, DefaultStyles? defaultStyles) {
Line line,
DefaultStyles? defaultStyles,
) {
final attrs = line.style.attributes;
if (attrs.containsKey(Attribute.header.key)) {
int level;
@ -1047,7 +1049,7 @@ class QuillRawEditorState extends EditorState
case 3:
return defaultStyles!.h3!.verticalSpacing;
default:
throw 'Invalid level $level';
throw ArgumentError('Invalid level $level');
}
}

@ -313,7 +313,7 @@ class EditableTextBlock extends StatelessWidget {
bottom = defaultStyles.h3!.verticalSpacing.bottom;
break;
default:
throw 'Invalid level $level';
throw ArgumentError('Invalid level $level');
}
} else {
final VerticalSpacing lineSpacing;

@ -274,7 +274,9 @@ class EditorTextSelectionOverlay {
}
void _handleSelectionHandleChanged(
TextSelection? newSelection, _TextSelectionHandlePosition position) {
TextSelection? newSelection,
_TextSelectionHandlePosition position,
) {
TextPosition textPosition;
switch (position) {
case _TextSelectionHandlePosition.start:
@ -288,7 +290,7 @@ class EditorTextSelectionOverlay {
: const TextPosition(offset: 0);
break;
default:
throw 'Invalid position';
throw ArgumentError('Invalid position');
}
final currSelection = newSelection != null
@ -393,7 +395,7 @@ class _TextSelectionHandleOverlay extends StatefulWidget {
case _TextSelectionHandlePosition.end:
return renderObject.selectionEndInViewport;
default:
throw 'Invalid position';
throw ArgumentError('Invalid position');
}
}
}
@ -481,7 +483,7 @@ class _TextSelectionHandleOverlayState
);
break;
default:
throw 'Invalid widget.position';
throw ArgumentError('Invalid widget.position');
}
if (newSelection.baseOffset >= newSelection.extentOffset) {

Loading…
Cancel
Save