home_screen.dart 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import 'widgets/home_drawer.dart';
  2. import 'widgets/editor_scaffold.dart';
  3. import 'package:flutter/material.dart';
  4. final flowyDocs = [
  5. 'plain_text_document.fdoc',
  6. 'block_document.fdoc',
  7. 'long_document.fdoc',
  8. ];
  9. class HomeScreen extends StatefulWidget {
  10. @override
  11. _HomeScreenState createState() => _HomeScreenState();
  12. }
  13. class _HomeScreenState extends State<HomeScreen> {
  14. String filename;
  15. Widget _editor;
  16. @override
  17. void initState() {
  18. filename = flowyDocs[1];
  19. super.initState();
  20. }
  21. @override
  22. Widget build(BuildContext context) {
  23. return HomeDrawer(
  24. drawer: Container(
  25. constraints: BoxConstraints(minWidth: 250, maxWidth: 250),
  26. color: Colors.white,
  27. child: ListView.separated(
  28. itemBuilder: (context, index) {
  29. return GestureDetector(
  30. onTap: () => _selectDoc(index),
  31. child: Container(
  32. padding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 16.0),
  33. child: Align(
  34. alignment: Alignment.centerLeft,
  35. child: Text(
  36. flowyDocs[index],
  37. style: TextStyle(fontSize: 16.0, color: Colors.black54),
  38. ),
  39. ),
  40. ),
  41. );
  42. },
  43. itemCount: flowyDocs.length,
  44. separatorBuilder: (context, index) => Divider(),
  45. ),
  46. ),
  47. body: _editor ?? _homepageEditor(),
  48. );
  49. }
  50. Widget _homepageEditor() {
  51. return EditorScaffold(filename: filename);
  52. }
  53. void _selectDoc(int index) {
  54. final filename = flowyDocs[index];
  55. setState(() {
  56. _editor = null;
  57. this.filename = filename;
  58. });
  59. }
  60. }