I'm trying to put the label of an TextField on right, but I don't know how. The text is ok, but the problem is about the label.
TextField(
enabled: this.enable,
enableInteractiveSelection: false,
autofocus: false,
textAlign: TextAlign.right,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: this.label,
hintText: this.hint,
alignLabelWithHint: true,
errorText: snapshot.hasError ? snapshot.error : null),
obscureText: this.obscure,
controller: _controller,
);
Does someone could help me how to put the labelText on the right as well?
you can use Directionality.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _MyHomePageState();
}
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Padding(
padding: EdgeInsets.all(30),
child: Directionality(
textDirection: TextDirection.rtl,
child: TextField(
textAlign: TextAlign.right,
autofocus: true,
decoration: new InputDecoration(
border: OutlineInputBorder(),
labelText: "ایمیل",
hintText: "ایمیل خود را وارد کنید"
),
)
)
),
)
);
}
}