-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(neon): Support custom backgrounds
Signed-off-by: jld3103 <[email protected]>
- Loading branch information
1 parent
041ae0a
commit 298abbd
Showing
9 changed files
with
150 additions
and
41 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
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
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
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
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,59 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:neon/blocs.dart'; | ||
import 'package:neon/nextcloud.dart'; | ||
import 'package:neon/src/utils/hex_color.dart'; | ||
import 'package:neon/src/utils/provider.dart'; | ||
import 'package:neon/src/widgets/image.dart'; | ||
|
||
@internal | ||
class NeonCustomBackground extends StatelessWidget { | ||
const NeonCustomBackground({ | ||
required this.theme, | ||
required this.child, | ||
super.key, | ||
}); | ||
|
||
final CoreThemingPublicCapabilities_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 = NeonCachedImage.url( | ||
url: theme!.background, | ||
account: NeonProvider.of<AccountsBloc>(context).activeAccount.value, | ||
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!, | ||
], | ||
), | ||
); | ||
} | ||
} |