@@ -98,92 +98,97 @@ class _CommentsTabPagesState extends State<CommentsTabPages> {
9898
9999 return Container (
100100 color: Colors .white,
101- child: Column (
102- children: < Widget > [
103- Expanded (
104- child: StreamBuilder <CommentsTabState >(
105- stream: bloc.state$,
106- initialData: bloc.state$.value,
107- builder: (context, snapshot) {
108- final state = snapshot.data;
101+ child: StreamBuilder <CommentsTabState >(
102+ stream: bloc.state$,
103+ initialData: bloc.state$.value,
104+ builder: (context, snapshot) {
105+ final state = snapshot.data;
109106
110- if (state.isLoading) {
111- return Center (
112- child: CircularProgressIndicator (),
113- );
114- }
115-
116- if (state.error != null ) {
117- return Center (
118- child: Text ('Error ${state .error }' ),
119- );
120- }
121-
122- final comments = state.comments;
123- return Scrollbar (
124- child: ListView .separated (
125- physics: const BouncingScrollPhysics (),
126- itemCount: comments.length,
127- itemBuilder: (context, index) => CommentItemWidget (
128- comment: comments[index],
129- deleteCallback: showDeleteDialog,
130- editCallback: showEditDialog,
131- ),
132- separatorBuilder: (context, index) => Divider (
133- color: Theme .of (context).dividerColor.withAlpha (128 ),
134- ),
135- ),
136- );
137- },
138- ),
139- ),
140- Container (
141- padding: const EdgeInsets .all (8.0 ),
142- decoration: BoxDecoration (
143- color: Colors .white,
144- boxShadow: [
145- BoxShadow (
146- color: Colors .grey,
147- blurRadius: 4 ,
148- )
149- ],
150- ),
151- child: Row (
107+ return Column (
152108 children: < Widget > [
153109 Expanded (
154- child: TextField (
155- controller: commentController,
156- expands: false ,
157- focusNode: focusNode,
158- decoration: InputDecoration (
159- labelText: 'Comment' ,
160- border: OutlineInputBorder (
161- borderRadius: BorderRadius .circular (32 ),
162- borderSide: const BorderSide (width: 0 ),
163- ),
164- filled: true ,
165- ),
166- onSubmitted: (_) => bloc.submitAddComment (),
167- keyboardType: TextInputType .multiline,
168- textInputAction: TextInputAction .newline,
169- maxLines: null ,
110+ child: Builder (
111+ builder: (context) {
112+ if (state.isLoading) {
113+ return Center (
114+ child: CircularProgressIndicator (),
115+ );
116+ }
117+
118+ if (state.error != null ) {
119+ return Center (
120+ child: Text ('Error ${state .error }' ),
121+ );
122+ }
123+
124+ final comments = state.comments;
125+ return Scrollbar (
126+ child: ListView .separated (
127+ physics: const BouncingScrollPhysics (),
128+ itemCount: comments.length,
129+ itemBuilder: (context, index) => CommentItemWidget (
130+ comment: comments[index],
131+ deleteCallback: showDeleteDialog,
132+ editCallback: showEditDialog,
133+ ),
134+ separatorBuilder: (context, index) => Divider (
135+ color:
136+ Theme .of (context).dividerColor.withAlpha (128 ),
137+ ),
138+ ),
139+ );
140+ },
170141 ),
171142 ),
172- const SizedBox (width: 8 ),
173- FloatingActionButton (
174- onPressed: () {
175- focusNode.unfocus ();
176- bloc.submitAddComment ();
177- },
178- child: Icon (
179- Icons .send,
180- ),
181- )
143+ if (state.isLoggedIn)
144+ Container (
145+ padding: const EdgeInsets .all (8.0 ),
146+ decoration: BoxDecoration (
147+ color: Colors .white,
148+ boxShadow: [
149+ BoxShadow (
150+ color: Colors .grey,
151+ blurRadius: 4 ,
152+ )
153+ ],
154+ ),
155+ child: Row (
156+ children: < Widget > [
157+ Expanded (
158+ child: TextField (
159+ controller: commentController,
160+ expands: false ,
161+ focusNode: focusNode,
162+ decoration: InputDecoration (
163+ labelText: 'Comment' ,
164+ border: OutlineInputBorder (
165+ borderRadius: BorderRadius .circular (32 ),
166+ borderSide: const BorderSide (width: 0 ),
167+ ),
168+ filled: true ,
169+ ),
170+ onSubmitted: (_) => bloc.submitAddComment (),
171+ keyboardType: TextInputType .multiline,
172+ textInputAction: TextInputAction .newline,
173+ maxLines: null ,
174+ ),
175+ ),
176+ const SizedBox (width: 8 ),
177+ FloatingActionButton (
178+ onPressed: () {
179+ focusNode.unfocus ();
180+ bloc.submitAddComment ();
181+ },
182+ child: Icon (
183+ Icons .send,
184+ ),
185+ )
186+ ],
187+ ),
188+ )
182189 ],
183- ),
184- )
185- ],
186- ),
190+ );
191+ }),
187192 );
188193 }
189194
0 commit comments