Skip to content

Instantly share code, notes, and snippets.

@benhaxe
Created November 21, 2019 13:26
Show Gist options
  • Save benhaxe/988809acc90fb2a11871c80bc48e836a to your computer and use it in GitHub Desktop.
Save benhaxe/988809acc90fb2a11871c80bc48e836a to your computer and use it in GitHub Desktop.
class TextPage extends StatelessWidget {
final String endpoint;
final String selectedSubject;
final String searchQuery;
TextPage(
{Key key,
@required this.endpoint,
@required this.selectedSubject,
@required this.searchQuery})
: super(key: key);
@override
Widget build(BuildContext context) {
return NetworkWidget(
child: BaseChangeNotifierProvider<ResourcesViewModel>(
model: ResourcesViewModel(resourceServices: Provider.of(context)),
onModelReady: (model) => model.getResources(endpoint, selectedSubject, searchQuery),
builder: (context, model, child) =>
LayoutBuilder(builder: (context, constraint) {
var viewHeight = constraint.maxHeight;
var viewWidth = constraint.maxWidth;
switch (model.viewStateGet) {
case ViewStateGet.Loading:
return LeapsLoadIndicator.loadingPulse(viewHeight / 5);
case ViewStateGet.hasData:
return BuildTextResult(model.resources);
case ViewStateGet.Empty:
return Container(child: ResourceStateChangeWidget());
case ViewStateGet.Error:
return Center(
child: SearchErrorView()
);
default:
return Container();
}
}),
),
);
}
}
class BuildTextResult extends StatelessWidget {
final List<Resource> snapshot;
const BuildTextResult(this.snapshot);
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: snapshot.length,
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => TextReview(
resource: snapshot[index], isForLessonNote: false),
fullscreenDialog: true,
));
},
child: TextItem(resource: snapshot[index]));
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment