No momento, tenho um problema e não sei como resolvê-lo. Basicamente, tenho vários cartões na tela, cada um representando sua própria "tabela". Gostaria de rotular cada um deles com seu próprio índice. Em outras palavras, cada tabela deve ter "Tabela" com um índice anexado como título. Por exemplo, "Tabela 1, Tabela 2" etc. Criei um arquivo separado para a aparência básica do widget de cartão:
credenciais_tisch.dart
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:fabene_bestellungen/provider/tisch_provider.dart';
class TischCredentials extends ConsumerStatefulWidget {
const TischCredentials({super.key});
@override
ConsumerState<ConsumerStatefulWidget> createState() {
return _TischCredentialsState();
}
}
class _TischCredentialsState extends ConsumerState<TischCredentials> {
@override
Widget build(BuildContext context) {
//final tischIndex = ref.watch(tischProvider.notifier).state;
//tischIndexErhoehen(tischIndex);
return Card(
child: Column(
children: [
Row(
children: [
//Text("Tisch " + tischIndex.toString()),
IconButton(
icon: Icon(Icons.delete),
onPressed: () {},
),
IconButton(onPressed: () {}, icon: Icon(Icons.check))
],
),
SizedBox(
height: 8,
),
Container(
height: 50,
width: 50,
),
],
),
);
}
}
Eu queria implementar isso neste arquivo, mas não funcionou como eu esperava. Então, movi para a tela principal, com o mesmo resultado. Minha última tentativa é esta:
pedidos_tela_principal.dart
import 'package:fabene_bestellungen/widgets/tisch_credentials.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:fabene_bestellungen/provider/tisch_provider.dart';
class BestellungenMainSreen extends ConsumerWidget {
BestellungenMainSreen({super.key, required this.tischIndex});
int tischIndex = 0;
String tischIndexErhoehen(int i) {
i = ++i;
return i.toString();
}
@override
Widget build(BuildContext context, WidgetRef ref) {
String aktuellerIndex = tischIndexErhoehen(tischIndex);
return Scaffold(
appBar: AppBar(
title: Text('Bestellungen'),
),
body: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text('Tisch ' + aktuellerIndex),
TischCredentials(),
/* Container(
margin: EdgeInsets.all(10),
width: 100,
height: 200,
decoration:
BoxDecoration(border: Border.all(color: Colors.grey)),
),*/
Text('Tisch ' + tischIndexErhoehen(tischIndex)),
TischCredentials(),
/* Container(
margin: EdgeInsets.all(10),
alignment: Alignment(10, 10),
width: 100,
height: 100,
color: Colors.red,
),*/
Container(
margin: EdgeInsets.all(10),
alignment: Alignment(10, 10),
width: 100,
height: 100,
color: Colors.red,
),
Container(
margin: EdgeInsets.all(10),
width: 100,
height: 100,
color: Colors.red,
),
],
),
Column(
children: [
Container(
width: 100,
height: 800,
color: Colors.blue,
),
Container(
margin: EdgeInsets.all(10),
width: 100,
height: 100,
//color: Colors.red,
decoration:
BoxDecoration(shape: BoxShape.circle, color: Colors.red),
)
],
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.all(10),
width: 100,
height: 200,
decoration:
BoxDecoration(border: Border.all(color: Colors.grey)),
),
Container(
margin: EdgeInsets.all(10),
alignment: Alignment(10, 10),
width: 100,
height: 100,
color: Colors.red,
),
Container(
margin: EdgeInsets.all(10),
alignment: Alignment(10, 10),
width: 100,
height: 100,
color: Colors.red,
),
Container(
margin: EdgeInsets.all(10),
width: 100,
height: 100,
color: Colors.red,
),
],
),
],
),
);
}
}
Infelizmente, não sei dizer como resolver isso. O Riverpod seria uma opção? Ou seja, salvar o índice em um provedor, aumentá-lo e atribuí-lo aos widgets individuais? Ou resolver tudo por meio de um future? Ou criar uma lista e exibi-la nos cards?
Experimente isto:
A
tischIndex
variável armazenará o índice atual, portanto não há necessidade de passar nenhum valor para otischIndexErhoehen
método.Espero que isso ajude!