2
Hello!
I found many tutorials on the internet, but I could not implement any successfully. Most of these tutorials, work with the creation of 2 lists, an initial and a secondary to be manipulated. Is this really the best form of implementation? I’m using the Bloc standard. So I’m having some difficulty handling the data.
Follows code:
class FollowingPage extends StatefulWidget {
final Player players;
const FollowingPage({Key key, this.players}) : super(key: key);
@override
_FollowingPageState createState() => _FollowingPageState();
}
class _FollowingPageState extends State<FollowingPage> {
FollowingBloc _followingBloc;
TextEditingController editingController = TextEditingController();
@override
void initState() {
_followingBloc = FollowingBloc();
_followingBloc.dispatch(FollowingEventList(context: context));
super.initState();
}
@override
void dispose() {
_followingBloc.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return BlocBuilder<FollowingEvent, FollowingState>(
bloc: _followingBloc,
builder: (context, state) {
if (state is FollowingStateLoading) {
return Center(child: CircularProgressIndicator());
}
if (state is FollowingStateError) {
return Center(child: Text(state.message));
}
if (state is FollowingStateInitial) {
return Center(child: Text("Nenhuma informação."));
}
if (state is FollowingStateSuccess) {
Result _following = state.followingModel.result;
return Scaffold(
appBar: AppBarCustom(),
body: Container(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(7.0),
child: TextField(
onChanged: (text) {
},
controller: editingController,
decoration: InputDecoration(
labelText: "Procurar jogadores",
hintText: "Informe o nome do jogador",
prefixIcon: Icon(Icons.search),
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(25.0)))),
),
),
Divider(),
Expanded(
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: _following.players.length,
itemBuilder: (context, index) {
if (_following.players.isEmpty) {
return Container(
height: MediaQuery.of(context).size.height * 0.6,
child: Center(
child: Text(
"Você ainda não segue outros jogadores"),
),
);
}
Player _dataCurrent = _following.players[index];
return Card(
child: ListTile(
leading: CircleAvatar(
radius: 25,
backgroundImage: _dataCurrent.avatar != null
? NetworkImage(_dataCurrent.avatar)
: AssetImage('assets/img/person.png'),
backgroundColor: Colors.transparent,
),
//title: Text(_dataCurrent.name),
title: Text(_dataCurrent.name != null
? _dataCurrent.name
: "Não informado"),
trailing: Icon(Icons.arrow_forward_ios),
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => FollowingDetails(
player: _dataCurrent)));
},
),
);
},
),
),
],
),
),
);
}
return null;
});
}
}
As you may notice I’m still beginner. I just want to filter this list according to what the user inform!
I find it strange that even following the tutorials you did not use any
StreamBuilder
that is essential in the use of Bloc Pattern... I do not know the class you usedBlocBuilder<FollowingEvent, FollowingState>
, but I will formulate an answer with the way I use the Bloc and as soon as possible I will be answering your question.– Matheus Ribeiro
I’ll wait for your reply to show you where Streambuilder is. I separate these calls into another class! But I look forward to your contribution, my friend!
– Guto G