9 changed files with 114 additions and 6 deletions
			
			
		@ -0,0 +1,56 @@ | 
				
			|||||||
 | 
					import 'package:flutter/material.dart'; | 
				
			||||||
 | 
					import 'package:meta/meta.dart'; | 
				
			||||||
 | 
					import 'package:neon/src/utils/hex_color.dart'; | 
				
			||||||
 | 
					import 'package:neon/src/widgets/image.dart'; | 
				
			||||||
 | 
					import 'package:nextcloud/core.dart' as core; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@internal | 
				
			||||||
 | 
					class NeonCustomBackground extends StatelessWidget { | 
				
			||||||
 | 
					  const NeonCustomBackground({ | 
				
			||||||
 | 
					    required this.theme, | 
				
			||||||
 | 
					    required this.child, | 
				
			||||||
 | 
					    super.key, | 
				
			||||||
 | 
					  }); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  final core.ThemingPublicCapabilities_Theming? theme; | 
				
			||||||
 | 
					  final Widget? child; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  double _opacity(final BuildContext context) => Theme.of(context).brightness == Brightness.light ? 0.2 : 0.1; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @override | 
				
			||||||
 | 
					  Widget build(final BuildContext context) { | 
				
			||||||
 | 
					    if (theme == null) { | 
				
			||||||
 | 
					      return ColoredBox( | 
				
			||||||
 | 
					        color: Theme.of(context).colorScheme.background, | 
				
			||||||
 | 
					        child: child, | 
				
			||||||
 | 
					      ); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (theme?.backgroundPlain ?? true) { | 
				
			||||||
 | 
					      return ColoredBox( | 
				
			||||||
 | 
					        color: | 
				
			||||||
 | 
					            Color.lerp(HexColor(theme!.background), Theme.of(context).colorScheme.background, 1 - _opacity(context))!, | 
				
			||||||
 | 
					        child: child, | 
				
			||||||
 | 
					      ); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    final image = NeonUrlImage( | 
				
			||||||
 | 
					      url: theme!.background, | 
				
			||||||
 | 
					      fit: BoxFit.fill, | 
				
			||||||
 | 
					    ); | 
				
			||||||
 | 
					    return ColoredBox( | 
				
			||||||
 | 
					      color: Theme.of(context).colorScheme.background, | 
				
			||||||
 | 
					      child: Stack( | 
				
			||||||
 | 
					        children: [ | 
				
			||||||
 | 
					          Positioned.fill( | 
				
			||||||
 | 
					            child: Opacity( | 
				
			||||||
 | 
					              opacity: _opacity(context), | 
				
			||||||
 | 
					              child: image, | 
				
			||||||
 | 
					            ), | 
				
			||||||
 | 
					          ), | 
				
			||||||
 | 
					          if (child != null) child!, | 
				
			||||||
 | 
					        ], | 
				
			||||||
 | 
					      ), | 
				
			||||||
 | 
					    ); | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					} | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue