Skip to content

Commit

Permalink
Merge pull request #32 from Wiwo99/test
Browse files Browse the repository at this point in the history
Feat: Many extensions added, code refactoring
  • Loading branch information
jayeshpansheriya authored Apr 19, 2024
2 parents 0da7a0b + 96c9ace commit 44aab61
Show file tree
Hide file tree
Showing 35 changed files with 1,052 additions and 556 deletions.
1 change: 1 addition & 0 deletions example/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions example/ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
44 changes: 44 additions & 0 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, this.title}) : super(key: key);
final String? title;
MyHomePage({Key? key, this.title}) : super(key: key);

@override
_MyHomePageState createState() => _MyHomePageState();
Expand Down
19 changes: 18 additions & 1 deletion example/lib/widget_ext.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:awesome_extensions/awesome_extensions.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class WidgetExt extends StatelessWidget {
const WidgetExt({Key? key}) : super(key: key);
Expand Down Expand Up @@ -28,6 +29,22 @@ class WidgetExt extends StatelessWidget {

/// Text Widget
Text('Hello World').bold().fontSize(25).italic(),

Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget?>[
Container(
height: 100,
width: 100,
color: Colors.red,
).showIf(true), // or any condition
Container(
height: 100,
width: 100,
color: Colors.green,
).showIf(false), // or any condition
].notNullWidget(), // returns only not null widgets
),
],
),
);
Expand Down
92 changes: 90 additions & 2 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
intl:
dependency: transitive
description:
name: intl
sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf
url: "https://pub.dev"
source: hosted
version: "0.19.0"
leak_tracker:
dependency: transitive
description:
Expand Down Expand Up @@ -135,6 +143,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
url: "https://pub.dev"
source: hosted
version: "2.1.8"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -188,6 +204,70 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.6.1"
url_launcher:
dependency: transitive
description:
name: url_launcher
sha256: "0ecc004c62fd3ed36a2ffcbe0dd9700aee63bd7532d0b642a488b1ec310f492e"
url: "https://pub.dev"
source: hosted
version: "6.2.5"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
sha256: d4ed0711849dd8e33eb2dd69c25db0d0d3fdc37e0a62e629fe32f57a22db2745
url: "https://pub.dev"
source: hosted
version: "6.3.0"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
sha256: "9149d493b075ed740901f3ee844a38a00b33116c7c5c10d7fb27df8987fb51d5"
url: "https://pub.dev"
source: hosted
version: "6.2.5"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
sha256: ab360eb661f8879369acac07b6bb3ff09d9471155357da8443fd5d3cf7363811
url: "https://pub.dev"
source: hosted
version: "3.1.1"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
sha256: b7244901ea3cf489c5335bdacda07264a6e960b1c1b1a9f91e4bc371d9e68234
url: "https://pub.dev"
source: hosted
version: "3.1.0"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
sha256: "3692a459204a33e04bc94f5fb91158faf4f2c8903281ddd82915adecdb1a901d"
url: "https://pub.dev"
source: hosted
version: "2.3.0"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
sha256: ecf9725510600aa2bb6d7ddabe16357691b6d2805f66216a97d1b881e21beff7
url: "https://pub.dev"
source: hosted
version: "3.1.1"
vector_math:
dependency: transitive
description:
Expand All @@ -204,6 +284,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "13.0.0"
web:
dependency: transitive
description:
name: web
sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
sdks:
dart: ">=3.2.0-0 <4.0.0"
flutter: ">=2.10.0"
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.19.0"
75 changes: 75 additions & 0 deletions lib/async_extensions/async_snapshot_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,81 @@ part of '../awesome_extensions.dart';

/// An extension on [AsyncSnapshot] providing a [when] method.
extension AsyncSnapshotExt<T> on AsyncSnapshot<T> {
/// Check if the [AsyncSnapshot] has data.
bool get hasData =>
connectionState == ConnectionState.active ||
connectionState == ConnectionState.done && data != null;

/// Check if the [AsyncSnapshot] has an error.
bool get hasError => connectionState == ConnectionState.done && error != null;

/// Check if the [AsyncSnapshot] is still waiting for data.
bool get isLoading => connectionState == ConnectionState.waiting;

/// **Perform conditional actions based on the state of the [AsyncSnapshot].**
///
/// ️ **Key points:**
///
/// -️ Similar to [when], but allows [data] callback to be optional.
/// -️ If no [data] callback, calls [loading] callback instead.
/// -️ [isComplete] signifies a closed connection/stream.
///
/// **Example:**
///
/// ```dart
/// StreamBuilder(
/// stream: incomingMessagesStream,
/// builder: (context, snapshot) {
/// return snapshot.maybeWhen(
/// data: (data, isComplete) {
/// return Column(
/// children: [
/// Text('Latest Message: $data'),
/// if (isComplete) Text('Messages are complete'),
/// ],
/// );
/// },
/// error: (error, stackTrace) {
/// return Text('We have an error');
/// },
/// loading: () {
/// return CircularProgressIndicator();
/// },
/// );
/// },
/// );
/// ```
R maybeWhen<R>({
R Function(T data, bool isComplete)? data,
required R Function(Object error, StackTrace? stackTrace) error,
required R Function() loading,
}) {
switch (connectionState) {
case ConnectionState.none:
if (this.data is T) {
return data!(this.data as T, true);
} else {
return loading();
}
case ConnectionState.waiting:
return loading();
case ConnectionState.active:
if (hasError) {
return error(this.error!, stackTrace);
} else {
return data!(this.data as T, false);
}
case ConnectionState.done:
if (hasError) {
return error(this.error!, stackTrace!);
} else {
return data!(this.data as T, true);
}
}
}

/// Perform actions conditionally based on the state of the [AsyncSnapshot].
///
/// All cases are required, which allows returning a non-nullable value.
Expand Down
11 changes: 7 additions & 4 deletions lib/awesome_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,30 @@ export 'package:awesome_extensions/src/url_strategy.dart';
export 'package:awesome_extensions/src/widgets/avatar_image.dart';

part 'async_extensions/async_snapshot_extension.dart';
part 'color_extensions/color_extension.dart';
part 'context_extensions/dialog_extension.dart';
part 'context_extensions/media_query_extension.dart';
part 'context_extensions/navigation_extension.dart';
part 'context_extensions/snackbar_extension.dart';
part 'context_extensions/theme_extension.dart';
part 'date_extensions/date_extension.dart';
part 'double_extensions/size_box_extension.dart';
part 'list_extensions/list_extensions.dart';
part 'num_extensions/number_extension.dart';
part 'src/nil.dart';
part 'src/shimmer.dart';
part 'string_extensions/string_extension.dart';
part 'color_extensions/color_extension.dart';
part 'text_extensions/text_extension.dart';
part 'text_extensions/text_style_extension.dart';
part 'widget_extensions/align_extension.dart';
part 'widget_extensions/center_extension.dart';
part 'widget_extensions/common_extension.dart';
part 'widget_extensions/container_extension.dart';
part 'widget_extensions/expanded_extension.dart';
part 'widget_extensions/flexible_extension.dart';
part 'widget_extensions/gesture_detector_extension.dart';
part 'widget_extensions/opacity_extension.dart';
part 'widget_extensions/padding_extension.dart';
part 'widget_extensions/positioned_extension.dart';
part 'widget_extensions/shimmer_extension.dart';
part 'widget_extensions/tooltip_extension.dart';
part 'widget_extensions/expanded_extension.dart';
part 'widget_extensions/flexible_extension.dart';
part 'widget_extensions/positioned_extension.dart';
Loading

0 comments on commit 44aab61

Please sign in to comment.