Skip to content

Instantly share code, notes, and snippets.

@NijatTagizada
Last active June 3, 2024 11:52
Show Gist options
  • Save NijatTagizada/7945f89790bded9343b8469df6c315af to your computer and use it in GitHub Desktop.
Save NijatTagizada/7945f89790bded9343b8469df6c315af to your computer and use it in GitHub Desktop.
Example of Proxy Design Pattern
import 'package:flutter/material.dart';
abstract class Proxy {
Widget build(BuildContext context);
}
class SensitiveData implements Proxy {
@override
Widget build(BuildContext context) {
return const Text("Password is 1234");
}
}
class AccessChecker implements Proxy {
const AccessChecker({
required this.haveAccess,
required this.sensitiveData,
});
final Proxy sensitiveData;
final bool haveAccess;
@override
Widget build(BuildContext context) {
return haveAccess
? sensitiveData.build(context)
: const Text("You do not have access to this data");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment