-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added UI Animations and ScreenSize reestructure
- Loading branch information
1 parent
ad8de91
commit 257a74f
Showing
32 changed files
with
683 additions
and
431 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:sliver_tools/sliver_tools.dart'; | ||
|
||
import '../extensions/app_localization_extension.dart'; | ||
import 'app_cupertino_button.dart'; | ||
|
||
class AppAsyncWidget<T> extends StatelessWidget { | ||
const AppAsyncWidget({ | ||
required this.asyncValue, | ||
required this.child, | ||
super.key, | ||
this.onErrorRetry, | ||
}); | ||
|
||
final AsyncValue<T> asyncValue; | ||
final VoidCallback? onErrorRetry; | ||
final Widget child; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return switch (asyncValue) { | ||
AsyncData() => child, | ||
AsyncError(:final error) => Center( | ||
key: const ValueKey('error'), | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
Text( | ||
error.toString(), | ||
style: Theme.of(context).textTheme.titleLarge, | ||
), | ||
if (onErrorRetry != null) | ||
CupertinoButton( | ||
onPressed: onErrorRetry, | ||
child: Text(context.loc.retry), | ||
), | ||
], | ||
), | ||
), | ||
AsyncLoading() => const Center( | ||
key: ValueKey('loading'), | ||
child: Center( | ||
child: SizedBox( | ||
width: 32, | ||
height: 32, | ||
child: CircularProgressIndicator.adaptive(), | ||
), | ||
), | ||
), | ||
}; | ||
} | ||
} | ||
|
||
class AppAsyncSliver<T> extends StatelessWidget { | ||
const AppAsyncSliver({ | ||
required this.asyncValue, | ||
required this.child, | ||
this.onErrorRetry, | ||
super.key, | ||
}); | ||
|
||
final AsyncValue<T> asyncValue; | ||
final VoidCallback? onErrorRetry; | ||
final Widget Function(T) child; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SliverAnimatedSwitcher( | ||
duration: kThemeAnimationDuration, | ||
child: switch (asyncValue) { | ||
AsyncData(:final value) => child(value), | ||
AsyncError(:final error) => SliverFillRemaining( | ||
key: const ValueKey('error'), | ||
child: Padding( | ||
padding: const EdgeInsets.all(16), | ||
child: Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
Text( | ||
error.toString(), | ||
style: Theme.of(context).textTheme.titleLarge, | ||
textAlign: TextAlign.center, | ||
), | ||
if (onErrorRetry != null) | ||
Padding( | ||
padding: const EdgeInsets.only(top: 16), | ||
child: AppCupertinoButton.tinted( | ||
color: Theme.of(context).colorScheme.primary, | ||
onPressed: onErrorRetry, | ||
icon: const Icon(Icons.refresh), | ||
child: Text(context.loc.retry), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
AsyncLoading() => const SliverFillRemaining( | ||
key: ValueKey('loading'), | ||
child: Center( | ||
child: SizedBox( | ||
width: 32, | ||
height: 32, | ||
child: CircularProgressIndicator.adaptive(), | ||
), | ||
), | ||
), | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,103 @@ | ||
import 'package:flex_color_scheme/flex_color_scheme.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../extensions/theme_of_context_extension.dart'; | ||
|
||
///extended CupertinoButton to pass null values in the minimumSize and padding | ||
enum CupertinoButtonType { | ||
plain, | ||
gray, | ||
tinted, | ||
filled, | ||
} | ||
|
||
class AppCupertinoButton extends StatelessWidget { | ||
const AppCupertinoButton({ | ||
required this.child, | ||
required this.onPressed, | ||
super.key, | ||
this.color, | ||
this.disabledColor, | ||
this.padding, | ||
this.icon, | ||
this.padding = EdgeInsets.zero, | ||
this.minSize, | ||
this.borderRadius = const BorderRadius.all(Radius.circular(32)), | ||
this.type, | ||
}); | ||
|
||
const AppCupertinoButton.tinted({ | ||
required this.child, | ||
required this.onPressed, | ||
required this.color, | ||
super.key, | ||
this.disabledColor, | ||
this.icon, | ||
this.borderRadius = const BorderRadius.all(Radius.circular(12)), | ||
this.padding = const EdgeInsets.symmetric(horizontal: 16, vertical: 16), | ||
this.type = CupertinoButtonType.tinted, | ||
this.minSize, | ||
}); | ||
|
||
final Widget child; | ||
final Widget? icon; | ||
final VoidCallback? onPressed; | ||
final EdgeInsetsGeometry? padding; | ||
final double? minSize; | ||
final Color? color; | ||
final Color? disabledColor; | ||
final BorderRadius borderRadius; | ||
final CupertinoButtonType? type; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return CupertinoButton( | ||
disabledColor: disabledColor ?? CupertinoColors.quaternarySystemFill, | ||
onPressed: onPressed, | ||
padding: padding ?? EdgeInsets.zero, | ||
minSize: minSize ?? 0, | ||
borderRadius: BorderRadius.circular(32), | ||
color: color, | ||
child: child, | ||
final typeSize = type == null ? 0.0 : kMinInteractiveDimensionCupertino; | ||
return Theme( | ||
data: Theme.of(context).copyWith( | ||
cupertinoOverrideTheme: CupertinoThemeData( | ||
primaryColor: color ?? context.colorScheme.primary, | ||
primaryContrastingColor: color ?? context.colorScheme.primary, | ||
scaffoldBackgroundColor: color ?? context.colorScheme.primary, | ||
textTheme: const CupertinoTextThemeData( | ||
primaryColor: Colors.white, | ||
textStyle: TextStyle(), | ||
), | ||
), | ||
), | ||
child: Builder( | ||
builder: (context) { | ||
return CupertinoButton( | ||
disabledColor: | ||
disabledColor ?? CupertinoColors.quaternarySystemFill, | ||
onPressed: onPressed, | ||
padding: padding, | ||
minSize: minSize ?? typeSize, | ||
borderRadius: borderRadius, | ||
color: _calculateColor(context), | ||
child: Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
if (icon != null) | ||
Padding( | ||
padding: const EdgeInsets.only(right: 4), | ||
child: icon, | ||
), | ||
child, | ||
], | ||
), | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
|
||
Color? _calculateColor(BuildContext context) { | ||
return switch (type) { | ||
CupertinoButtonType.plain || null => null, | ||
CupertinoButtonType.gray => CupertinoColors.systemFill, | ||
CupertinoButtonType.tinted => color!.withOpacity(0.2), | ||
CupertinoButtonType.filled => context.colorScheme.primary.darken() | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// ignore_for_file: public_member_api_docs, sort_constructors_first | ||
import 'package:flutter/material.dart'; | ||
|
||
class AppLoadingIndicator extends StatelessWidget { | ||
const AppLoadingIndicator({ | ||
required this.showLoading, | ||
this.sliver = false, | ||
super.key, | ||
}); | ||
|
||
final bool showLoading; | ||
final bool sliver; | ||
@override | ||
Widget build(BuildContext context) { | ||
if (sliver) { | ||
return SliverToBoxAdapter( | ||
child: AnimatedSize( | ||
duration: const Duration(milliseconds: 300), | ||
child: !showLoading | ||
? const SizedBox.shrink() | ||
: const Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Padding( | ||
padding: EdgeInsets.all(16), | ||
child: SizedBox( | ||
height: 32, | ||
width: 32, | ||
child: CircularProgressIndicator.adaptive(), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
return AnimatedSize( | ||
duration: const Duration(milliseconds: 300), | ||
child: !showLoading | ||
? const SizedBox.shrink() | ||
: const Padding( | ||
padding: EdgeInsets.all(16), | ||
child: SizedBox( | ||
height: 32, | ||
width: 32, | ||
child: CircularProgressIndicator.adaptive(), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.