@ -1,76 +1,206 @@
/ / ignore_for_file: depend_on_referenced_packages , implementation_imports
/ / ignore_for_file: depend_on_referenced_packages , implementation_imports
import ' dart:async ' ;
import ' package:flutter/material.dart ' ;
import ' package:flutter/material.dart ' ;
import ' package:flutter_gen/gen_l10n/l10n.dart ' ;
import ' package:flutter_gen/gen_l10n/l10n.dart ' ;
import ' package:fluffychat/config/app_config.dart ' ;
import ' package:fluffychat/config/app_config.dart ' ;
import ' package:fluffychat/config/themes.dart ' ;
import ' package:fluffychat/config/themes.dart ' ;
import ' package:fluffychat/pangea/common/utils/overlay.dart ' ;
import ' package:fluffychat/pangea/constructs/construct_identifier.dart ' ;
import ' package:fluffychat/pangea/constructs/construct_identifier.dart ' ;
import ' package:fluffychat/pangea/morphs/get_grammar_copy.dart ' ;
import ' package:fluffychat/pangea/morphs/get_grammar_copy.dart ' ;
import ' package:fluffychat/pangea/morphs/morph_features_enum.dart ' ;
import ' package:fluffychat/pangea/morphs/morph_features_enum.dart ' ;
import ' package:fluffychat/pangea/morphs/morph_icon.dart ' ;
import ' package:fluffychat/pangea/morphs/morph_icon.dart ' ;
import ' package:fluffychat/widgets/matrix.dart ' ;
class ConstructNotificationUtil {
static Completer ? closeCompleter ;
static final Set < ConstructIdentifier > unlockedConstructs = { } ;
static bool showingNotification = false ;
static void addUnlockedConstruct (
List < ConstructIdentifier > constructs ,
BuildContext context ,
) {
unlockedConstructs . addAll ( constructs ) ;
if ( ! showingNotification ) {
showUnlockedMorphsSnackbar ( context ) ;
}
}
static void onClose ( ConstructIdentifier construct ) {
MatrixState . pAnyState . closeOverlay ( " ${ construct . string } _snackbar " ) ;
unlockedConstructs . remove ( construct ) ;
closeCompleter ? . complete ( ) ;
closeCompleter = null ;
}
static Future < void > showUnlockedMorphsSnackbar ( BuildContext context ) async {
showingNotification = true ;
while ( unlockedConstructs . isNotEmpty ) {
final construct = unlockedConstructs . first ;
try {
final copy = getGrammarCopy (
category: construct . category ,
lemma: construct . lemma ,
context: context ,
) ;
closeCompleter = Completer ( ) ;
OverlayUtil . showOverlay (
overlayKey: " ${ construct . string } _snackbar " ,
context: context ,
child: ConstructNotificationOverlay (
construct: construct ,
copy: copy ,
) ,
transformTargetId: " " ,
position: OverlayPositionEnum . top ,
backDropToDismiss: false ,
closePrevOverlay: false ,
canPop: false ,
) ;
await closeCompleter ! . future ;
} catch ( e ) {
showingNotification = false ;
break ;
}
}
showingNotification = false ;
}
}
class ConstructNotificationOverlay extends StatefulWidget {
final ConstructIdentifier construct ;
final String ? copy ;
const ConstructNotificationOverlay ( {
super . key ,
required this . construct ,
this . copy ,
} ) ;
@ override
State < ConstructNotificationOverlay > createState ( ) = >
ConstructNotificationOverlayState ( ) ;
}
void showUnlockedMorphsSnackbar (
class ConstructNotificationOverlayState
Set < ConstructIdentifier > unlockedConstructs ,
extends State < ConstructNotificationOverlay > with TickerProviderStateMixin {
BuildContext context ,
AnimationController ? _controller ;
) {
Animation < double > ? _animation ;
for ( final construct in unlockedConstructs ) {
final copy = getGrammarCopy (
@ override
category: construct . category ,
void initState ( ) {
lemma: construct . lemma ,
super . initState ( ) ;
context: context ,
_controller = AnimationController (
duration: FluffyThemes . animationDuration ,
vsync: this ,
) ;
_animation = CurvedAnimation (
parent: _controller ! ,
curve: Curves . easeInOut ,
) ;
) ;
ScaffoldMessenger . of ( context ) . showSnackBar (
SnackBar (
_controller ! . forward ( ) . then ( ( _ ) {
behavior: FluffyThemes . isColumnMode ( context )
Future . delayed ( const Duration ( seconds: 5 ) , ( ) {
? SnackBarBehavior . floating
if ( mounted ) _close ( ) ;
: SnackBarBehavior . fixed ,
} ) ;
width: FluffyThemes . isColumnMode ( context )
} ) ;
? MediaQuery . of ( context ) . size . width
}
: null ,
showCloseIcon: true ,
@ override
duration: const Duration ( seconds: 5 ) ,
void dispose ( ) {
dismissDirection: DismissDirection . none ,
_controller ? . dispose ( ) ;
backgroundColor: Theme . of ( context ) . colorScheme . surface ,
super . dispose ( ) ;
content: Padding (
}
padding: const EdgeInsets . all ( 8.0 ) ,
child: Wrap (
void _close ( ) {
spacing: 16.0 ,
_controller ? . reverse ( ) . then ( ( _ ) {
alignment: WrapAlignment . center ,
ConstructNotificationUtil . onClose ( widget . construct ) ;
crossAxisAlignment: WrapCrossAlignment . center ,
} ) ;
}
@ override
Widget build ( BuildContext context ) {
return Material (
type: MaterialType . transparency ,
child: SizeTransition (
sizeFactor: _animation ! ,
axisAlignment: - 1.0 ,
child: Container (
padding: const EdgeInsets . symmetric ( vertical: 16.0 ) ,
decoration: BoxDecoration (
color: Theme . of ( context ) . colorScheme . surface ,
border: Border (
bottom: BorderSide (
color: Theme . of ( context ) . colorScheme . onSurface . withAlpha ( 50 ) ,
) ,
) ,
) ,
child: Row (
children: [
children: [
Text (
const SizedBox (
L10n . of ( context ) . youUnlocked ,
width: 50.0 ,
style: TextStyle (
height: 50.0 ,
fontSize: FluffyThemes . isColumnMode ( context ) ? 32.0 : 16.0 ,
color: Theme . of ( context ) . colorScheme . onSurface ,
fontWeight: FontWeight . bold ,
) ,
) ,
) ,
Row (
Expanded (
mainAxisSize: MainAxisSize . min ,
child: Wrap (
spacing: 16.0 ,
spacing: 16.0 ,
children: [
alignment: WrapAlignment . center ,
Flexible (
crossAxisAlignment: WrapCrossAlignment . center ,
child: Text (
children: [
copy ? ? construct . lemma ,
Text (
L10n . of ( context ) . youUnlocked ,
style: TextStyle (
style: TextStyle (
fontSize:
fontSize:
FluffyThemes . isColumnMode ( context ) ? 32.0 : 16.0 ,
FluffyThemes . isColumnMode ( context ) ? 32.0 : 16.0 ,
color: AppConfig . gold ,
color: Theme. of ( context ) . colorScheme . onSurface ,
fontWeight: FontWeight . bold ,
fontWeight: FontWeight . bold ,
) ,
) ,
overflow: TextOverflow . ellipsis ,
) ,
) ,
) ,
Row (
MorphIcon (
mainAxisSize: MainAxisSize . min ,
morphFeature: MorphFeaturesEnumExtension . fromString (
spacing: 16.0 ,
construct . category ,
children: [
Flexible (
child: Text (
widget . copy ? ? widget . construct . lemma ,
style: TextStyle (
fontSize: FluffyThemes . isColumnMode ( context )
? 32.0
: 16.0 ,
color: AppConfig . gold ,
fontWeight: FontWeight . bold ,
) ,
overflow: TextOverflow . ellipsis ,
) ,
) ,
MorphIcon (
morphFeature: MorphFeaturesEnumExtension . fromString (
widget . construct . category ,
) ,
morphTag: widget . construct . lemma ,
) ,
] ,
) ,
) ,
morphTag: construct . lemma ,
] ,
) ,
) ,
Container (
alignment: Alignment . center ,
width: 50.0 ,
child: IconButton (
icon: const Icon (
Icons . close ,
) ,
) ,
] ,
onPressed: _close ,
) ,
) ,
) ,
] ,
] ,
) ,
) ,