string_obfuscation 0.1.2
string_obfuscation: ^0.1.2 copied to clipboard
A build_runner generator that obfuscates Dart string literals at build time.
import 'package:flutter/material.dart';
import 'package:string_obfuscation/string_obfuscation.dart';
part 'main.gen.dart';
@ClassEncrypt(encryptKey: 'example-key')
abstract class AppStrings {
@StringEncrypt(value: 'String obfuscation')
String get appTitle;
@StringEncrypt(value: 'Generated strings are ready to use.')
String get welcomeMessage;
String get startButton;
}
@ClassJsonGenerator(encryptKey: 'example-key')
class User {
final String name;
final int? age;
const User({required this.name, this.age});
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
Map<String, dynamic> toJson() => _$UserToJson(this);
}
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
print(User(name: 'name').toJson());
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text(appStrings.appTitle),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(appStrings.welcomeMessage),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () {},
child: Text(appStrings.startButton),
),
],
),
),
),
);
}
}