.github
android
api
assets
debian
ios
lib
controllers
providers
screens
types
widgets
account
attachment
chat
navigation
app_background.dart
app_bottom_navigation.dart
app_drawer_navigation.dart
app_rail_navigation.dart
app_scaffold.dart
post
about.dart
app_bar_leading.dart
connection_indicator.dart
context_menu.dart
dialog.dart
link_preview.dart
loading_indicator.dart
markdown_content.dart
notify_indicator.dart
unauthorized_hint.dart
universal_image.dart
version_label.dart
firebase_options.dart
main.dart
router.dart
theme.dart
linux
macos
snap
web
windows
.gitignore
.metadata
.roadsignrc
README.md
analysis_options.yaml
build.yaml
devtools_options.yaml
firebase.json
pubspec.lock
pubspec.yaml
roadsign.toml
78 lines
2.1 KiB
Dart
78 lines
2.1 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
import 'package:responsive_framework/responsive_framework.dart';
|
|
|
|
class AppBackground extends StatelessWidget {
|
|
final Widget child;
|
|
final bool isRoot;
|
|
|
|
const AppBackground({
|
|
super.key,
|
|
required this.child,
|
|
this.isRoot = false,
|
|
});
|
|
|
|
Widget _buildWithBackgroundImage(
|
|
BuildContext context,
|
|
File imageFile,
|
|
Widget child,
|
|
) {
|
|
final devicePixelRatio = MediaQuery.of(context).devicePixelRatio;
|
|
|
|
final size = MediaQuery.of(context).size;
|
|
return Container(
|
|
color: Theme.of(context).colorScheme.surface,
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
backgroundBlendMode: BlendMode.darken,
|
|
color: Theme.of(context).colorScheme.surface,
|
|
image: DecorationImage(
|
|
opacity: 0.2,
|
|
image: ResizeImage(
|
|
FileImage(imageFile),
|
|
width: (size.width * devicePixelRatio).round(),
|
|
height: (size.height * devicePixelRatio).round(),
|
|
policy: ResizeImagePolicy.fit,
|
|
),
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
child: child,
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ScaffoldMessenger(
|
|
child: FutureBuilder(
|
|
future: kIsWeb ? Future.value(null) : getApplicationDocumentsDirectory(),
|
|
builder: (context, snapshot) {
|
|
if (isRoot || ResponsiveBreakpoints.of(context).smallerOrEqualTo(MOBILE)) {
|
|
if (snapshot.hasData) {
|
|
final path = '${snapshot.data!.path}/app_background_image';
|
|
final file = File(path);
|
|
if (file.existsSync()) {
|
|
return _buildWithBackgroundImage(context, file, child);
|
|
}
|
|
}
|
|
|
|
return Material(
|
|
color: Theme.of(context).colorScheme.surface,
|
|
child: child,
|
|
);
|
|
}
|
|
|
|
return Material(
|
|
color: Colors.transparent,
|
|
child: child,
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|