apply_code_screen.dart 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import "package:flutter/material.dart";
  2. import "package:photos/extensions/input_formatter.dart";
  3. import "package:photos/theme/ente_theme.dart";
  4. import "package:photos/ui/components/button_widget.dart";
  5. import "package:photos/ui/components/icon_button_widget.dart";
  6. import "package:photos/ui/components/models/button_type.dart";
  7. import "package:photos/ui/components/title_bar_title_widget.dart";
  8. import "package:photos/ui/components/title_bar_widget.dart";
  9. class ApplyCodeScreen extends StatefulWidget {
  10. const ApplyCodeScreen({super.key});
  11. @override
  12. State<ApplyCodeScreen> createState() => _ApplyCodeScreenState();
  13. }
  14. class _ApplyCodeScreenState extends State<ApplyCodeScreen> {
  15. late TextEditingController _textController;
  16. late FocusNode textFieldFocusNode;
  17. String code = "";
  18. @override
  19. void initState() {
  20. _textController = TextEditingController();
  21. textFieldFocusNode = FocusNode();
  22. super.initState();
  23. }
  24. @override
  25. void dispose() {
  26. _textController.dispose();
  27. textFieldFocusNode.dispose();
  28. super.dispose();
  29. }
  30. @override
  31. Widget build(BuildContext context) {
  32. final colorScheme = getEnteColorScheme(context);
  33. final textStyle = getEnteTextTheme(context);
  34. textFieldFocusNode.requestFocus();
  35. return Scaffold(
  36. body: CustomScrollView(
  37. primary: false,
  38. slivers: <Widget>[
  39. TitleBarWidget(
  40. flexibleSpaceTitle: const TitleBarTitleWidget(
  41. title: "Apply code",
  42. ),
  43. actionIcons: [
  44. IconButtonWidget(
  45. icon: Icons.close_outlined,
  46. iconButtonType: IconButtonType.secondary,
  47. onTap: () {
  48. // Go three screen back, similar to pop thrice
  49. Navigator.of(context)
  50. ..pop()
  51. ..pop()
  52. ..pop();
  53. },
  54. ),
  55. ],
  56. ),
  57. SliverList(
  58. delegate: SliverChildBuilderDelegate(
  59. (delegateBuildContext, index) {
  60. return Padding(
  61. padding: const EdgeInsets.symmetric(horizontal: 16),
  62. child: Padding(
  63. padding: const EdgeInsets.symmetric(vertical: 20),
  64. child: Column(
  65. mainAxisSize: MainAxisSize.min,
  66. children: [
  67. Column(
  68. children: [
  69. Text(
  70. "Enter the code provided by your friend to "
  71. "claim free storage for both of you",
  72. style: textStyle.small
  73. .copyWith(color: colorScheme.textMuted),
  74. ),
  75. const SizedBox(height: 24),
  76. _getInputField(),
  77. // Container with 8 border radius and red color
  78. ],
  79. ),
  80. ],
  81. ),
  82. ),
  83. );
  84. },
  85. childCount: 1,
  86. ),
  87. ),
  88. SliverFillRemaining(
  89. child: SafeArea(
  90. child: Padding(
  91. padding: const EdgeInsets.all(12.0),
  92. child: Column(
  93. mainAxisAlignment: MainAxisAlignment.end,
  94. children: [
  95. ButtonWidget(
  96. buttonType: ButtonType.neutral,
  97. buttonSize: ButtonSize.large,
  98. labelText: "Apply",
  99. isDisabled: code.trim().length < 4,
  100. onTap: () async {
  101. debugPrint("yet to implement");
  102. },
  103. )
  104. ],
  105. ),
  106. ),
  107. ),
  108. ),
  109. ],
  110. ),
  111. );
  112. }
  113. Widget _getInputField() {
  114. return TextFormField(
  115. controller: _textController,
  116. focusNode: textFieldFocusNode,
  117. style: getEnteTextTheme(context).body,
  118. inputFormatters: [UpperCaseTextFormatter()],
  119. textCapitalization: TextCapitalization.sentences,
  120. decoration: InputDecoration(
  121. focusedBorder: OutlineInputBorder(
  122. borderRadius: const BorderRadius.all(Radius.circular(4.0)),
  123. borderSide:
  124. BorderSide(color: getEnteColorScheme(context).strokeMuted),
  125. ),
  126. fillColor: getEnteColorScheme(context).fillFaint,
  127. filled: true,
  128. hintText: 'Enter referral code',
  129. contentPadding: const EdgeInsets.symmetric(
  130. horizontal: 16,
  131. vertical: 14,
  132. ),
  133. border: UnderlineInputBorder(
  134. borderSide: BorderSide.none,
  135. borderRadius: BorderRadius.circular(8),
  136. ),
  137. ),
  138. onChanged: (value) {
  139. code = value.trim();
  140. setState(() {});
  141. },
  142. autocorrect: false,
  143. keyboardType: TextInputType.emailAddress,
  144. textInputAction: TextInputAction.next,
  145. );
  146. }
  147. }