#flutter #validation #tabs
#flutter #проверка #вкладки
Вопрос:
class CadastrarCliente extends StatefulWidget {
Cliente cliente;
Veiculo veiculo;
CadastrarCliente({this.cliente, this.veiculo});
@override
_CadastrarClienteState createState() => _CadastrarClienteState();
}
User u = User();
UserHelper h = UserHelper();
Future<User> getAssociacao() async {
u = await h.getUser();
return u;
}
class _CadastrarClienteState extends State<CadastrarCliente>
with SingleTickerProviderStateMixin {
Cliente _editedCliente;
Veiculo _editedVeiculo;
Future<User> usuario;
var idAssociacao;
String valorFipe;
int _currentStep = 0;
var value, label;
Financeiro financeiro = Financeiro();
// final _formkey = GlobalKey<FormState>();
List<GlobalKey<FormState>> _formkeys = [
GlobalKey<FormState>(),
GlobalKey<FormState>(),
GlobalKey<FormState>(),
GlobalKey<FormState>(),
GlobalKey<FormState>()
];
final scaffoldKey = new GlobalKey<ScaffoldState>();
TabController _tabController;
int _selectedIndex = 0;
List<Widget> listTab = [
Tab(text: 'Cliente'),
Tab(text: 'Veículo'),
Tab(text: 'Contrato'),
Tab(text: 'Financeiro'),
];
var _checkboxZeroKm = false;
DateTime _dataNota;
var _ctrlIdAssociacao = TextEditingController();
@override
void initState() {
super.initState();
_tabController = TabController(length: listTab.length, vsync: this);
veryfi swiper:
_tabController.addListener(() {
setState(() {
print(
'Testando ${_formkeys[_tabController.index - 1].currentState} e Index ${(_tabController.index - 1).toString()}');
if (_formkeys[_tabController.index - 1].currentState.validate()) {
print("Selected Index: " (_tabController.index).toString());
}
});
});
if (widget.cliente == null) {
_editedCliente = Cliente();
} else {
_editedCliente = widget.cliente;
_editedVeiculo = widget.veiculo;
}
}
Widget build(BuildContext context) {
return DefaultTabController(
length: 4,
child: Scaffold(
key: scaffoldKey,
appBar: AppBar(
backgroundColor: Color(0xFF00b3c9),
bottom: TabBar(
onTap: (index) {},
controller: _tabController,
tabs: listTab,
),
title: Text('Cotação de Veículos'),
),
body: TabBarView(
physics: ClampingScrollPhysics(), //NeverScrollableScrollPhysics()
controller: _tabController,
children: [
Form(key: _formkeys[0], child: FormCliente()),
Form(key: _formkeys[1], child: FormVeiculo()),
Form(key: _formkeys[2], child: FormContrato()),
Form(key: _formkeys[3], child: FormFinanceiro(valorFipe)),
],
),
),
);
}
}
Комментарии:
1. Вы нашли решение для этого?