Related
I'm new developing with Flutter. I'm now using MobX to manage my app states and using Provider to pass the instance of my MobX Controller through screens.
The app is simple, where the user go through the screens answering the questions. Everytime a question is answered, the answer is saved on the MobX Controller. Everytime the user go to the next screen or return to the previous screen, if the field has an answer, the MobX Controller fill that answer. So, if the user return to the Main screen and start to answer the questions again, he will start where he stoped. All is working until the end of the questions.
When the user finish the answers, all the data is saved to Firebase and I need to "restart" the MobX Controller. But when I create a new instance of the MobX Controller and pass it to the older instance, the Provider insist in keep the old instance, with all the old answers.
I've tried a lot of things, and the only and incorrect way to make it works, was changing every variable of the class manually. And this is so sad, because is too much fields.
So, the question is: How can I create a new instance of my MobX Controller and make the Provider use this new instance?
Principal.dart: (the main screen of app)
void main() {
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
runApp(
MultiProvider(
providers: [
Provider<Controller>(
create: (BuildContext context) => Controller(),
)
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Colors.black
),
home: Main(),
),
)
);
}
class Main extends StatefulWidget {
const Main({Key? key}) : super(key: key);
#override
State<Main> createState() => _MainState();
}
class _MainState extends State<Main> {
Controller controller_mobx = Controller();
int _conexao = 0; // 0 - SEM CONEXAO | 1 - CONECTADO
#override
void didChangeDependencies() {
// TODO: implement didChangeDependencies
super.didChangeDependencies();
controller_mobx = Provider.of(context);
}
#override
void initState() {
// TODO: implement initState
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp
]);
}
#override
Widget build(BuildContext context) {
Util cores = Util();
verificar_conexao();
double altura_imagem =MediaQuery.of(context).size.height/5;
controller_mobx.preenche_lista_vistoria();
FlutterNativeSplash.remove();
return Container(
width: double.infinity,
height: double.infinity,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/wallpaper.png'),
//colorFilter: ColorFilter.mode(Colors.white.withOpacity(0.75), BlendMode.modulate,),
fit: BoxFit.cover
)
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.all(16),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
height: altura_imagem,
child: Image.asset("images/logo.png"),
),
Padding(
padding: EdgeInsets.only(top: 16, bottom: 8),
child: Container(
height: 50,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.all(Radius.circular(15)),
border: Border.all(
color: cores.laranja_teccel,
width: 2
),
),
child: Material(
borderRadius: BorderRadius.all(Radius.circular(15)),
child: InkWell(
splashColor: cores.laranja_teccel.withOpacity(0.25),
hoverColor: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(12)),
onTap: (){
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NovaVistoria()
)
);
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding:EdgeInsets.only(left: 4),
child: Icon(
Icons.directions_car_rounded,
color: cores.cor_app_bar,
size: 30,
),
),
Align(
alignment: Alignment.center,
child: Text(
"Nova Vistoria",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 14,
),
),
),
Padding(
padding:EdgeInsets.only(right: 4),
child: Icon(
Icons.directions_car_rounded,
color: cores.cor_app_bar,
size: 30,
),
),
],
)
),
)
)
),
],
),
)
],
),
);
}
verificar_conexao() async{
Util verif = Util();
_conexao = await verif.verificar_conexao();
if(_conexao == 0){
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SemConexao()
)
);
}
else{
return;
}
}
}
NovaVistoria.dart: (the screen used to manage each tab of questions on app)
class NovaVistoria extends StatefulWidget {
#override
State<NovaVistoria> createState() => _NovaVistoriaState();
}
class _NovaVistoriaState extends State<NovaVistoria> {
Controller controller_mobx = Controller();
#override
void didChangeDependencies() {
// TODO: implement didChangeDependencies
super.didChangeDependencies();
controller_mobx = Provider.of(context);
}
Util cores = Util();
#override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
height: double.infinity,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/wallpaper.png'),
//colorFilter: ColorFilter.mode(Colors.white.withOpacity(0.75), BlendMode.modulate,),
fit: BoxFit.cover
)
),
child: Scaffold(
backgroundColor: Colors.transparent,
appBar: PreferredSize(
preferredSize: Size.fromHeight(50),
child: AppBar(
title: Text('Nova Vistoria', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white),),
backgroundColor: cores.cor_app_bar,
automaticallyImplyLeading: true,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
bottom: Radius.circular(10),
),
),
),
),
body: Observer(
builder: (_){
return Padding(
padding: EdgeInsets.all(8),
child: controller_mobx.abas[controller_mobx.indice_tela]
);
},
)
),
);
}
}
AbaDados.dart: (the first tab of questions)
class AbaDados extends StatefulWidget {
const AbaDados({Key? key}) : super(key: key);
#override
State<AbaDados> createState() => _AbaDadosState();
}
class _AbaDadosState extends State<AbaDados> {
Controller controller_mobx = Controller();
#override
void didChangeDependencies() {
// TODO: implement didChangeDependencies
super.didChangeDependencies();
controller_mobx = Provider.of(context);
}
#override
Widget build(BuildContext context) {
DateTime now = DateTime.now();
String data_relatorio = DateFormat('dd/MM/yyyy kk:mm:ss').format(now);
if(controller_mobx.data.isEmpty)
_controller_data.text = data_relatorio;
else
_controller_data.text = controller_mobx.data;
_controller_vistoriador.text = controller_mobx.vistoriador;
_controller_condutor.text = controller_mobx.condutor;
_controller_modelo.text = controller_mobx.modelo_veiculo;
_controller_placa.text = controller_mobx.placa;
return Observer(
builder: (_){
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.only(bottom: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: Text(
"1 - Dados da Vistoria",
style: TextStyle(
color: cores.laranja_teccel,
fontSize: 24,
fontWeight: FontWeight.bold
),
)
)
]
),
),
Padding(
padding: EdgeInsets.only(top: 8, bottom: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: Container(
height: 50,
child: TextField(
enabled: false,
controller: _controller_data,
keyboardType: TextInputType.name,
textCapitalization: TextCapitalization.characters,
textInputAction: TextInputAction.next,
cursorColor: cores.cor_app_bar,
style: TextStyle(
color: cores.cor_app_bar,
fontSize: 14,
fontWeight: FontWeight.bold
),
decoration: InputDecoration(
floatingLabelBehavior: FloatingLabelBehavior.always,
counterText: "",
labelText: "Data da Vistoria",
labelStyle: TextStyle(color: cores.laranja_teccel, fontWeight: FontWeight.normal),
fillColor: Colors.transparent,
hoverColor: cores.cor_app_bar,
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: cores.cor_app_bar),
borderRadius: BorderRadius.circular(15),
),
disabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: cores.cor_app_bar),
borderRadius: BorderRadius.circular(15),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: cores.laranja_teccel),
borderRadius: BorderRadius.circular(15),
),
),
onSubmitted: (content){
},
),
),
)
]
),
),
Padding(
padding: EdgeInsets.only(top: 8, bottom: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: Container(
height: 50,
child: TextField(
controller: _controller_vistoriador,
focusNode: _foco_vistoriador,
keyboardType: TextInputType.name,
textCapitalization: TextCapitalization.characters,
textInputAction: TextInputAction.next,
cursorColor: cores.cor_app_bar,
style: TextStyle(
color: cores.cor_app_bar,
fontSize: 14,
fontWeight: FontWeight.bold
),
decoration: InputDecoration(
floatingLabelBehavior: FloatingLabelBehavior.always,
counterText: "",
labelText: "Vistoriador",
labelStyle: TextStyle(color: cores.laranja_teccel, fontWeight: FontWeight.normal),
fillColor: Colors.transparent,
hoverColor: cores.cor_app_bar,
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: cores.cor_app_bar),
borderRadius: BorderRadius.circular(15),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: cores.laranja_teccel),
borderRadius: BorderRadius.circular(15),
),
),
onSubmitted: (content){
},
),
),
)
]
),
),
Padding(
padding: EdgeInsets.only(top: 8, bottom: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: Container(
height: 50,
child: TextField(
controller: _controller_condutor,
focusNode: _foco_condutor,
keyboardType: TextInputType.name,
textCapitalization: TextCapitalization.characters,
textInputAction: TextInputAction.next,
cursorColor: cores.cor_app_bar,
style: TextStyle(
color: cores.cor_app_bar,
fontSize: 14,
fontWeight: FontWeight.bold
),
decoration: InputDecoration(
floatingLabelBehavior: FloatingLabelBehavior.always,
counterText: "",
labelText: "Condutor",
labelStyle: TextStyle(color: cores.laranja_teccel, fontWeight: FontWeight.normal),
fillColor: Colors.transparent,
hoverColor: cores.cor_app_bar,
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: cores.cor_app_bar),
borderRadius: BorderRadius.circular(15),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: cores.laranja_teccel),
borderRadius: BorderRadius.circular(15),
),
),
onSubmitted: (content){
},
),
),
)
]
),
),
Padding(
padding: EdgeInsets.only(top: 8, bottom: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: Container(
height: 50,
child: TextField(
controller: _controller_modelo,
focusNode: _foco_modelo,
keyboardType: TextInputType.text,
textCapitalization: TextCapitalization.characters,
textInputAction: TextInputAction.next,
cursorColor: cores.cor_app_bar,
style: TextStyle(
color: cores.cor_app_bar,
fontSize: 14,
fontWeight: FontWeight.bold
),
decoration: InputDecoration(
floatingLabelBehavior: FloatingLabelBehavior.always,
counterText: "",
labelText: "Modelo do Veículo",
labelStyle: TextStyle(color: cores.laranja_teccel, fontWeight: FontWeight.normal),
fillColor: Colors.transparent,
hoverColor: cores.cor_app_bar,
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: cores.cor_app_bar),
borderRadius: BorderRadius.circular(15),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: cores.laranja_teccel),
borderRadius: BorderRadius.circular(15),
),
),
onSubmitted: (content){
},
),
),
)
]
),
),
Padding(
padding: EdgeInsets.only(top: 8, bottom: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: Container(
height: 50,
child: TextField(
controller: _controller_placa,
focusNode: _foco_placa,
keyboardType: TextInputType.text,
textCapitalization: TextCapitalization.characters,
textInputAction: TextInputAction.done,
cursorColor: cores.cor_app_bar,
style: TextStyle(
color: cores.cor_app_bar,
fontSize: 14,
fontWeight: FontWeight.bold
),
decoration: InputDecoration(
floatingLabelBehavior: FloatingLabelBehavior.always,
counterText: "",
labelText: "Placa",
labelStyle: TextStyle(color: cores.laranja_teccel, fontWeight: FontWeight.normal),
fillColor: Colors.transparent,
hoverColor: cores.cor_app_bar,
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: cores.cor_app_bar),
borderRadius: BorderRadius.circular(15),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: cores.laranja_teccel),
borderRadius: BorderRadius.circular(15),
),
),
),
),
)
]
),
),
Expanded(child: Container()),
Padding(
padding: EdgeInsets.only(top: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: Container(
height: 50,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.all(Radius.circular(15)),
border: Border.all(
color: cores.laranja_teccel,
width: 2
),
),
child: Material(
borderRadius: BorderRadius.all(Radius.circular(15)),
child: InkWell(
splashColor: cores.laranja_teccel.withOpacity(0.25),
hoverColor: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(12)),
onTap: (){
salvar_dados();
},
child: Align(
alignment: Alignment.center,
child: Text(
"Avançar",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 14,
),
),
),
),
)
),
)
]
),
),
],
);
},
);
}
salvar_dados(){
if(_controller_vistoriador.text.isEmpty || _controller_condutor.text.isEmpty ||
_controller_modelo.text.isEmpty || _controller_placa.text.isEmpty){
final snackBar = SnackBar(
content: const Text('Existem campos obrigatórios não preenchidos. Verifique e tente novamente'),
backgroundColor: cores.cor_accent,
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
else{
controller_mobx.salvar_dados_iniciais(_controller_data.text, _controller_vistoriador.text, _controller_condutor.text, _controller_modelo.text, _controller_placa.text);
Controller controller_novo = Controller();
controller_mobx = controller_novo;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Main()
)
);
}
}
For this question, I changed the lenght of the app, so it finishes on the first tab. On the last rows, we save the data, create a new instance of controller_mobx and then return to the main screen.
Where I'm creating a new Controller instance:
Controller controller_novo = Controller();
controller_mobx = controller_novo;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Main()
)
);
So, after we finish and return to the Main Screen, the Controller must be without data. But when we start to answer the questions again, the fields are filled with the old answers. On the gif below I show the problem:
problem
Any help will be appreciate. Please, explain in details for best understanding.
How it should work:
what I need
What I needed to do to make it work:
[...]
#observable
bool vistoria_finalizada = false;
#action
alterar_vistoria_finalizada(bool valor){
vistoria_finalizada = valor;
if(valor){
data = "";
vistoriador = "";
condutor = "";
modelo_veiculo = "";
placa = "";
}
}
[...]
I want to achieve this type of alert dialogue. so, far I able to achieve this.
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text('Enter Time'),
content:
Builder(builder: (context) {
var height = 100;
var width = 60;
return Container(
height: height - 10,
width: width - 10,
child: Row(
children: [
Expanded(
flex: 2,
child: TextField(
onChanged: (value) {
setState(() {
// valueText = value;
});
},
decoration:
const InputDecoration(
hintText: "Hour",
//helperText: 'Hour',
),
),
),
const Expanded(
child: Center(
child: Text(
":",
style: TextStyle(
fontSize: 50),
),
)),
Expanded(
flex: 2,
child: TextField(
onChanged: (value) {
setState(() {
// valueText = value;
});
},
decoration:
const InputDecoration(
hintText:
"Min",
// helperText: 'Min',
),
),
),
],
),
);
}),
actions: <Widget>[
ElevatedButton(
child: Text('OK'),
onPressed: () {
setState(() {
// codeDialog = valueText;
Navigator.pop(context);
});
},
),
],
);
});
this my code and still need lots of improvements and guide me with suitable suggestions
can anybody give me overhead on how to make it achieve the same UI as above
note: I am asking for learning purposes only and am amazed if this UI is achievable through custom.
Here is the full code solution. You just have to do little tweaking of fonts and padding stuff And of course add the functionality. I have created the UI for you.
import 'package:flutter/material.dart';
class Hello extends StatefulWidget {
const Hello({Key? key}) : super(key: key);
#override
State<Hello> createState() => _HelloState();
}
class _HelloState extends State<Hello> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: TextButton(
child: Text('Show Dialog'),
onPressed: () {
showDialog(
context: context,
builder: (_) => SimpleDialog(
children: [
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20.0, vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'ENTER TIME',
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 20.0),
child: Row(
children: [
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
color: Colors.grey,
height: 80,
width: 120,
child: TextFormField(
keyboardType: TextInputType.datetime,
showCursor: false,
initialValue: '15',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 70,
color: Colors.black,
),
decoration: InputDecoration(
border: InputBorder.none,
),
),
),
Text('Hour'),
],
),
Text(
':',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.black,
fontSize: 70,
),
),
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
color: Colors.grey,
height: 80,
width: 120,
child: TextFormField(
keyboardType: TextInputType.datetime,
showCursor: false,
initialValue: '15',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 70,
color: Colors.black,
),
decoration: InputDecoration(
border: InputBorder.none,
),
),
),
Text('Minute'),
],
),
],
),
),
SizedBox(
height: 40,
),
Row(
children: [
Icon(Icons.access_time_outlined),
Spacer(),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(
'Cancel',
style: TextStyle(
color: Colors.black,
),
),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(
'OK',
style: TextStyle(
color: Colors.black,
),
),
),
],
),
],
),
),
],
),
);
},
),
),
);
}
}
Just do TimeObject = await showTimePicker(etc) instead of showDialog
Try this and edit for your wish
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text('Enter Time'),
content: Builder(builder: (context) {
var height = 100;
var width = 60;
return Container(
height: height - 50,
width: width - 30,
child: Row(
children: [
Expanded(
flex: 2,
child: DecoratedBox(
decoration: BoxDecoration(
color: Colors.grey,
borderRadius:
BorderRadius.circular(5),
),
child: TextField(
onChanged: (value) {
setState(() {
// valueText = value;
});
},
decoration: const InputDecoration(
hintText: "Hour",
border: UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
errorBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
enabledBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
focusedBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
disabledBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
focusedErrorBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
),
),
),
),
const Expanded(
flex: 1, child: Text(":")),
Expanded(
flex: 2,
child: DecoratedBox(
decoration: BoxDecoration(
color: Colors.grey,
borderRadius:
BorderRadius.circular(5),
),
child: TextField(
onChanged: (value) {
setState(() {
// valueText = value;
});
},
decoration: const InputDecoration(
hintText: "Min",
border: UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
errorBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
enabledBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
focusedBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
disabledBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
focusedErrorBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
),
),
),
),
],
),
);
}),
actions: <Widget>[
ElevatedButton(
child: Text('OK'),
onPressed: () {
setState(() {
// codeDialog = valueText;
Navigator.pop(context);
});
},
),
],
);
});
Try this and keep posted.
I have face a issue in flutter textfield , When I am trying to use underline property in my code - show some field good some issued.
How can I solve this issue, help me someone
Here is the issue :
This is my reuseable code :
import 'package:flutter/material.dart';
import '../../configs/appColors.dart';
class LoginSignUpFormField extends StatelessWidget {
const LoginSignUpFormField({
Key? key,
required this.labelText,
required this.icons,
this.controller,
}) : super(key: key);
final String? labelText;
final IconData icons;
final TextEditingController? controller;
#override
Widget build(BuildContext context) {
return TextField(
controller: controller,
autocorrect: true,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green),
),
// enabledBorder: UnderlineInputBorder(
// borderSide: BorderSide(color: black45),
// ),
// focusedBorder: UnderlineInputBorder(
// borderSide: BorderSide(color: black45),
// ),
// border: UnderlineInputBorder(
// borderSide: BorderSide(color: black45),
// ),
hintText: labelText,
hintStyle: TextStyle(
color: black45,
fontSize: 15,
),
prefixIcon: Icon(
icons,
color: black45,
),
),
);
}
}
This is SignUp screen Code :
import 'package:duaredoctor_app/src/configs/appColors.dart';
import 'package:duaredoctor_app/src/configs/appUtils.dart';
import 'package:duaredoctor_app/src/pages/loginPage.dart';
import 'package:duaredoctor_app/src/widgets/formField/loginSignUpForm.dart';
import 'package:duaredoctor_app/src/widgets/kText.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class RegisterPage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: ListView(
// physics: NeverScrollableScrollPhysics(),
children: [
FittedBox(
child: Container(
height: Get.height,
width: Get.width,
child: Stack(
clipBehavior: Clip.none,
children: [
Container(
alignment: Alignment.center,
height: 150,
width: Get.width,
color: green50,
child: KText(
text: 'REGISTER',
color: white,
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
Positioned(
top: 130,
child: Container(
height: Get.height,
width: Get.width,
decoration: BoxDecoration(
color: white,
borderRadius: BorderRadius.circular(20),
),
child: Padding(
padding: paddingH10V10,
child: Column(
children: [
sizeH40,
LoginSignUpFormField(
labelText: 'Full name',
icons: Icons.person_outlined,
),
sizeH20,
LoginSignUpFormField(
labelText: 'Email',
icons: Icons.email_outlined,
),
sizeH20,
LoginSignUpFormField(
labelText: 'Phone',
icons: Icons.call_outlined,
),
sizeH20,
LoginSignUpFormField(
labelText: 'Password',
icons: Icons.lock_outline,
),
sizeH20,
LoginSignUpFormField(
labelText: 'Password',
icons: Icons.lock_outline,
),
sizeH30,
Container(
height: 40,
width: Get.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: greenDark,
),
child: Center(
child: KText(
text: 'Login',
fontSize: 17,
color: white,
),
),
),
sizeH30,
Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [
KText(
text: 'Already have an account?',
fontSize: 16,
color: black54,
),
InkWell(
onTap: () => Get.to(LoginPage()),
child: Padding(
padding: paddingH10,
child: KText(
text: 'Login',
fontWeight: FontWeight.bold,
fontSize: 17,
color:
Color.fromARGB(255, 75, 174, 255),
),
),
),
],
),
],
),
),
),
),
],
),
),
)
],
),
),
);
}
}
this is an example how to do it
TextField(
................
.....................
border: InputBorder.none,
)
make all border to InputBorder.none, that is (focusedErrorBorder,focusedBorder,enabledBorder,errorBorder,etc...)
I am have this app that uses a checkbox to receive inputs from users, for example select a type of storage you want (NVMe, ssd, hdd etc) i want a solution that if a checkbox or multiple checkboxes are selected, it outputs their values on the summary screen.I have tried youtube tutorials, i did not quite understand them. Here is my code thanks
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:signoff_app/Screens/preview.dart';
import 'package:signoff_app/storage/store.dart';
import 'package:signoff_app/widget/textformfields.dart';
class NewSign extends StatefulWidget {
NewSign({Key? key}) : super(key: key);
#override
State<NewSign> createState() => _NewSignState();
}
class _NewSignState extends State<NewSign> {
bool ssd = false;
bool hdd = false;
bool nvme = false;
bool m2 = false;
TextEditingController pcname = new TextEditingController();
TextEditingController motherboard = new TextEditingController();
TextEditingController casing = new TextEditingController();
TextEditingController ramSize = new TextEditingController();
TextEditingController ram = new TextEditingController();
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.red,
title: Text(
'Sign Off a Computer',
style: GoogleFonts.lato(
fontSize: 16,
fontStyle: FontStyle.normal,
),
),
),
body: Container(
width: MediaQuery.of(context).size.width,
// color: Colors.black54,
child: Stack(
children: [
Container(
//margin: EdgeInsets.fromLTRB(24, 0, 0, 24),
padding: EdgeInsets.fromLTRB(32, 64, 32, 32),
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
// color: Colors.black54,
child: Column(
children: [
Expanded(
flex: 1,
child: SizedBox(
width: 100,
height: 100,
child: Image(
fit: BoxFit.contain,
image: AssetImage("./images/udlogo.png"),
),
),
),
Expanded(
flex: 3,
child: Column(
children: [
Row(
children: [
Expanded(
flex: 2,
child: TextFormField(
controller: pcname,
validator: (val) {
if (val!.isEmpty) {
return "required";
}
},
decoration: InputDecoration(
labelText: 'Pc Name',
// errorText: 'please enter pc name'
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6),
borderSide: BorderSide(
color: Colors.blue,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
borderSide: BorderSide(
color: Colors.grey,
width: 1.5,
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
borderSide: BorderSide(
color: Colors.red,
width: 1.5,
),
),
),
),
),
SizedBox(
width: 24,
),
Expanded(
flex: 2,
child: TextFormField(
controller: motherboard,
decoration: InputDecoration(
labelText: 'MotherBoard',
// errorText: 'please enter pc name'
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6),
borderSide: BorderSide(
color: Colors.blue,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
borderSide: BorderSide(
color: Colors.grey,
width: 1.5,
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
borderSide: BorderSide(
color: Colors.red,
width: 1.5,
),
),
),
),
),
],
),
SizedBox(
height: 62,
),
Row(
children: [
Expanded(
flex: 2,
child: TextFormField(
controller: ram,
validator: (val) {
if (val!.isEmpty) {
return "required";
}
},
decoration: InputDecoration(
labelText: 'Ram',
// errorText: 'please enter pc name'
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6),
borderSide: BorderSide(
color: Colors.blue,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
borderSide: BorderSide(
color: Colors.grey,
width: 1.5,
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
borderSide: BorderSide(
color: Colors.red,
width: 1.5,
),
),
),
),
),
SizedBox(
width: 24,
),
Expanded(
flex: 2,
child: TextFormField(
controller: casing,
decoration: InputDecoration(
labelText: 'Casing',
// errorText: 'please enter pc name'
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6),
borderSide: BorderSide(
color: Colors.blue,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
borderSide: BorderSide(
color: Colors.grey,
width: 1.5,
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
borderSide: BorderSide(
color: Colors.red,
width: 1.5,
),
),
),
),
),
],
),
SizedBox(height: 24),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Storage',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w900,
),
),
SizedBox(height: 8),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
//ssd checkbox
Text("SSD"),
SizedBox(width: 2),
Checkbox(
value: ssd,
onChanged: (bool? value) {
setState(() {
ssd = value!;
});
},
),
//hdd checkbox
SizedBox(width: 16),
Text("HDD"),
SizedBox(width: 2),
Checkbox(
value: hdd,
onChanged: (bool? value) {
setState(() {
hdd = value!;
});
},
),
SizedBox(width: 16),
//Nvme checkbox
Text("NVMe"),
SizedBox(width: 2),
Checkbox(
value: nvme,
onChanged: (bool? value) {
setState(() {
ssd = value!;
});
},
),
//m.2 checkbox
SizedBox(width: 16),
Text("M.2"),
SizedBox(width: 2),
Checkbox(
value: m2,
onChanged: (bool? value) {
setState(() {
m2 = value!;
});
},
),
],
),
],
),
],
),
),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomCenter,
child: SizedBox(
width: MediaQuery.of(context).size.width,
height: 45,
child: ElevatedButton(
style:
ElevatedButton.styleFrom(primary: Colors.red),
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => PreviewSel(pcname.text,
motherboard.text, ram.text, casing.text),
),
);
},
child: Text('Submit'),
),
),
),
),
],
),
),
],
),
),
),
);
}
}
It seems to me that you have everything to now create your Text component. You update the booleans using setState in such a way that tapping the checkbox will update the state value, allowing you to use these variables inside a Widget, which will update when one of the values changes.
final String _summary = 'ssd: $ssd, hdd: $hdd, nvme: $nvme m2: $m2';
print(_summary); // 'ssd: false, hdd: false, nvme: false, m2: false';
...
Text(_summary);
I need to center my column vertically i try with mainAxisAlignment and crossAxisAlignment but dont know why its not coming in center. Here is my code
return Container(
height: stackHeight * 0.4,
decoration: BoxDecoration(
color: Color(0xff404040),
borderRadius: BorderRadius.only(topLeft: Radius.circular(15.0), topRight: Radius.circular(15.0))
),
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 10, left: 10, right:10,
bottom: MediaQuery.of(context).viewInsets.bottom + 10 ,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
TextField(
maxLength: 56,
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
decoration: InputDecoration(
counterText: '',
labelText: 'Would Question',
labelStyle: TextStyle(
color: Colors.blue
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
),
),
onSubmitted: (_) => _submitData(),
),
TextField(
maxLength: 56,
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
decoration: InputDecoration(
counterText: '',
labelText: 'Rather Question',
labelStyle: TextStyle(
color: Colors.red
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
),
keyboardType: TextInputType.number,
onSubmitted: (_) => _submitData(),
),
RaisedButton(onPressed: () {
_submitData();
}, child: Text('Add Question', style: TextStyle(
color: Colors.white
),),color: Theme.of(context).primaryColor,
),
],
),
),
],
),
),
);
Also, don't know on border-radius its showing white corners as you see in image emulator I need to remove this white also.
also, When i am opening the keyboard its cover the whole bottomsheet nothing is showing also the yellow line error showing is it possible when keyboard open the bottom shettup move on up side
You can give a transparent background so it will remove the white corners. Color.fromRGBO(255, 0, 0, 0.5)
Also can wrap center with Singlescroll widget. As mention in the above answer.
Wrap your SingleChildScrollView widget with Center widget. And for white corner you can wrap your main container with other container and set color: new Color.fromRGBO(255, 0, 0, 0.5),
Working Code here
return Container(
color: new Color.fromRGBO(255, 0, 0, 0.5),
child: Container(
height: stackHeight * 0.4,
decoration: BoxDecoration(
color: Color(0xff404040),
borderRadius: BorderRadius.only(topLeft: Radius.circular(15.0), topRight: Radius.circular(15.0))
),
child: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 10, left: 10, right:10,
bottom: MediaQuery.of(context).viewInsets.bottom + 10 ,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
TextField(
maxLength: 56,
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
decoration: InputDecoration(
counterText: '',
labelText: 'Would Question',
labelStyle: TextStyle(
color: Colors.blue
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
),
),
onSubmitted: (_) => _submitData(),
),
TextField(
maxLength: 56,
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
decoration: InputDecoration(
counterText: '',
labelText: 'Rather Question',
labelStyle: TextStyle(
color: Colors.red
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
),
keyboardType: TextInputType.number,
onSubmitted: (_) => _submitData(),
),
RaisedButton(onPressed: () {
_submitData();
}, child: Text('Add Question', style: TextStyle(
color: Colors.white
),),color: Theme.of(context).primaryColor,
),
],
),
),
],
),
),
),
),
);
Use this
crossAxisAlignment: CrossAxisAlignment.center,
instead of this
crossAxisAlignment: CrossAxisAlignment.end,
SAMPLE CODE
return Container(
height: stackHeight * 0.4,
decoration: BoxDecoration(
color: Color(0xff404040),
borderRadius: BorderRadius.only(topLeft: Radius.circular(15.0), topRight: Radius.circular(15.0))
),
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 10, left: 10, right:10,
bottom: MediaQuery.of(context).viewInsets.bottom + 10 ,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
TextField(
maxLength: 56,
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
decoration: InputDecoration(
counterText: '',
labelText: 'Would Question',
labelStyle: TextStyle(
color: Colors.blue
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
),
),
onSubmitted: (_) => _submitData(),
),
TextField(
maxLength: 56,
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
decoration: InputDecoration(
counterText: '',
labelText: 'Rather Question',
labelStyle: TextStyle(
color: Colors.red
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
),
keyboardType: TextInputType.number,
onSubmitted: (_) => _submitData(),
),
RaisedButton(onPressed: () {
_submitData();
}, child: Text('Add Question', style: TextStyle(
color: Colors.white
),),color: Theme.of(context).primaryColor,
),
],
),
),
],
),
),
);