nsfw_detect 1.2.7
nsfw_detect: ^1.2.7 copied to clipboard
On-device NSFW/nudity detection for iOS and Android photo libraries. CoreML + Vision on iOS, TensorFlow Lite on Android. Progressive result streaming, body part detection, and ready-to-use gallery widgets.
example/lib/main.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:nsfw_detect/nsfw_detect.dart';
import 'screens/gallery_screen.dart';
import 'screens/headless_scan_screen.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
// Enable native logging in debug builds — visible in Flutter console
if (kDebugMode) {
NsfwDetector.instance.setLogging(true);
}
runApp(const NsfwDetectExampleApp());
}
class NsfwDetectExampleApp extends StatelessWidget {
const NsfwDetectExampleApp({super.key});
@override
Widget build(BuildContext context) => MaterialApp(
title: 'NSFW Detect Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: const Color(0xFF2196F3),
brightness: Brightness.dark,
),
useMaterial3: true,
scaffoldBackgroundColor: const Color(0xFF121212),
appBarTheme: const AppBarTheme(
backgroundColor: Color(0xFF1E1E1E),
foregroundColor: Colors.white,
elevation: 0,
),
),
home: const _RootNav(),
);
}
class _RootNav extends StatefulWidget {
const _RootNav();
@override
State<_RootNav> createState() => _RootNavState();
}
class _RootNavState extends State<_RootNav> {
int _index = 0;
static const _screens = <Widget>[
GalleryScreen(),
HeadlessScanScreen(),
];
@override
Widget build(BuildContext context) => Scaffold(
body: IndexedStack(index: _index, children: _screens),
bottomNavigationBar: NavigationBar(
backgroundColor: const Color(0xFF1A1A1A),
selectedIndex: _index,
onDestinationSelected: (i) => setState(() => _index = i),
destinations: const [
NavigationDestination(
icon: Icon(Icons.photo_library_outlined),
selectedIcon: Icon(Icons.photo_library),
label: 'Gallery',
),
NavigationDestination(
icon: Icon(Icons.code_outlined),
selectedIcon: Icon(Icons.code),
label: 'Headless',
),
],
),
);
}