Created
October 10, 2021 14:51
-
-
Save diamantidis/3b2fc85453e2efc7565271717194ea9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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