Last active
June 3, 2024 11:52
-
-
Save NijatTagizada/7945f89790bded9343b8469df6c315af to your computer and use it in GitHub Desktop.
Example of Proxy Design Pattern
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
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