Skip to content

Commit

Permalink
adedd some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
VB10 committed Apr 20, 2023
1 parent ac33df1 commit 99fa5b6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 43 deletions.
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import 'package:provider/provider.dart';

import 'package:use_case_flutter/core/init/main_build.dart';
import 'package:use_case_flutter/product/init/enviroment/http_log_manager.dart';
import 'package:use_case_flutter/use_case/cancalable_auto_complete/auto_cancalable_view.dart';
import 'package:use_case_flutter/use_case/global_management/provider/global_manage_provider.dart';
import 'package:use_case_flutter/use_case/text_field_without_controller/login_view.dart';

void main() => runApp(
Provider(
Expand Down Expand Up @@ -42,7 +42,7 @@ class _MyAppState extends State<MyApp> {
// brightness: Brightness.light,
// ),
),
home: const AutoCancelableView(),
home: const LoginView(),
navigatorObservers: [ChuckerFlutter.navigatorObserver],
),
);
Expand Down
3 changes: 1 addition & 2 deletions lib/use_case/text_field_without_controller/clear_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class ClearTextAction extends Action<ClearTextIntent> {
}

class ClearTextIntent extends Intent {
final String? text;

const ClearTextIntent({this.text});
final String? text;
}
98 changes: 59 additions & 39 deletions lib/use_case/text_field_without_controller/login_view.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
import 'package:flutter/material.dart';
import 'package:use_case_flutter/use_case/text_field_without_controller/clear_action.dart';

mixin LoginController on State<LoginView> {
final TextEditingController _controller = TextEditingController();

@override
void dispose() {
super.dispose();
_controller.dispose();
}

void updateController(List args) {}
}

class LoginView extends StatefulWidget {
const LoginView({Key? key}) : super(key: key);
const LoginView({super.key});
@override
State<LoginView> createState() => _LoginViewState();
}
Expand All @@ -33,49 +21,47 @@ class _LoginViewState extends State<LoginView> with LoginController {
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: Row(
mainAxisSize: MainAxisSize.min,
children: [
_homeButton(),
_removeButton(),
],
),
appBar: AppBar(),
body: _CustomTextField(
action: textAction,
onChange: (String value) {
_value = value;
},
));
floatingActionButton: Row(
mainAxisSize: MainAxisSize.min,
children: [
_homeButton(),
_removeButton(),
],
),
appBar: AppBar(),
body: _CustomTextField(
action: textAction,
onChange: (String value) {
_value = value;
},
),
);
}

FloatingActionButton _homeButton() {
return FloatingActionButton.large(
child: const Icon(Icons.home),
onPressed: () {
_controllerCleaner.update('home');
_controllerCleaner.update('vb');
},
);
}

FloatingActionButton _removeButton() {
return FloatingActionButton(
onPressed: _controllerCleaner.clear,
child: const Icon(Icons.remove),
onPressed: () {
_controllerCleaner.clear();
},
);
}
}

class _CustomTextField extends StatelessWidget {
_CustomTextField({
Key? key,
required this.action,
required this.onChange,
}) : super(key: key);
});

final TextEditingController controller = TextEditingController();
final TextEditingController _controller = TextEditingController();
final ClearTextAction action;
final void Function(String value) onChange;
@override
Expand All @@ -85,15 +71,15 @@ class _CustomTextField extends StatelessWidget {
listener: (action) {
if (action is ClearTextAction) {
if (action.text.isEmpty) {
controller.clear();
_controller.clear();
} else {
controller.text = action.text;
_controller.text = action.text;
}
}
},
child: TextField(
onChanged: onChange,
controller: controller,
controller: _controller,
decoration: const InputDecoration(
border: OutlineInputBorder(),
),
Expand All @@ -103,9 +89,8 @@ class _CustomTextField extends StatelessWidget {
}

class ControllerCleaner {
final ClearTextAction _clearTextAction;

ControllerCleaner(ClearTextAction clearTextAction) : _clearTextAction = clearTextAction;
final ClearTextAction _clearTextAction;

void clear() {
_clearTextAction.invoke(const ClearTextIntent());
Expand All @@ -115,3 +100,38 @@ class ControllerCleaner {
_clearTextAction.invoke(ClearTextIntent(text: title));
}
}

mixin LoginController on State<LoginView> {
final TextEditingController _controller = TextEditingController();

@override
void dispose() {
super.dispose();
_controller.dispose();
}

void updateController(List args) {}
}

// class XS extends StatelessWidget {
// const XS({super.key});
// final textController = TextEditingController();
// @override
// Widget build(BuildContext context) {
// return Column(
// children: [
// TextField(
// controller: textController,
// ),
// ElevatedButton(
// onPressed: () {
// textController.clear();
// textController.text = "";
// textController.dispose();
// },
// child: const Text('Clear'),
// ),
// ],
// );
// }
// }

0 comments on commit 99fa5b6

Please sign in to comment.