Skip to content

Instantly share code, notes, and snippets.

@diamantidis
Created October 10, 2021 14:51
Show Gist options
  • Save diamantidis/3b2fc85453e2efc7565271717194ea9e to your computer and use it in GitHub Desktop.
Save diamantidis/3b2fc85453e2efc7565271717194ea9e to your computer and use it in GitHub Desktop.
class ArticlePage extends StatelessWidget {
final List<Section> sections;
const ArticlePage({Key? key, required this.sections}) : super(key: key);
@override
Widget build(BuildContext context) {
final tableOfContents = TableOfContents(
sections: sections,
onItemTap: (section) {
final targetContext = section.key.currentContext;
if (targetContext != null) {
Scrollable.ensureVisible(
targetContext,
duration: const Duration(milliseconds: 400),
curve: Curves.easeInOut,
);
}
},
);
final listView = ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: sections.length,
itemBuilder: (BuildContext context, int index) {
final section = sections[index];
return SectionWidget(
key: section.key,
section: section,
);
},
);
return Scaffold(
appBar: AppBar(
title: const Text('Home Screen'),
),
body: SafeArea(
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
tableOfContents,
listView,
],
),
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment