Advertisement
Guest User

Untitled

a guest
Sep 9th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.11 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import './NewProjectSheet.dart';
  3. import 'package:path_provider/path_provider.dart';
  4. import 'dart:io';
  5. import './MenuItem.dart';
  6. import './../../../core/Project.dart';
  7.  
  8. class HomePage extends StatefulWidget{
  9.  
  10.   @override
  11.   _HomePageState createState() => _HomePageState();
  12.  
  13. }
  14.  
  15. class _HomePageState extends State<HomePage> {
  16.  
  17.   Directory _dir;
  18.  
  19.   void _showModalSheet() {
  20.  
  21.     showModalBottomSheet(
  22.  
  23.       context: context,
  24.  
  25.       builder: (builder) {
  26.  
  27.         return NewProjectSheet();
  28.  
  29.       }
  30.  
  31.     );
  32.  
  33.   }
  34.  
  35.   @override
  36.   void initState() {
  37.     super.initState();
  38.     getApplicationDocumentsDirectory().then((dir){
  39.  
  40.       setState(() {
  41.  
  42.         _dir = dir;
  43.              
  44.       });
  45.  
  46.     });
  47.   }
  48.  
  49.   List<Widget> getMenuItems(){
  50.  
  51.     print("getting items!");
  52.  
  53.     if(_dir != null)
  54.       return _dir.listSync()
  55.                       .where((f) => f is File)
  56.                       .map((f) => f as File)
  57.                       .where((f) => f.path.endsWith(".pfile.json"))
  58.                       .map((f) => f.readAsStringSync())
  59.                       .map((s) => MenuItem(Project.fromJSonString(s)))
  60.                       .toList();
  61.     print("was null");
  62.                      
  63.     return [];
  64.  
  65.   }
  66.  
  67.   @override
  68.   Widget build(BuildContext context){
  69.  
  70.  
  71.     return Scaffold(
  72.  
  73.       floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
  74.       floatingActionButton: FloatingActionButton(
  75.  
  76.         child: Icon(Icons.add),
  77.  
  78.         onPressed: _showModalSheet,
  79.  
  80.       ),
  81.  
  82.       body: GridView.count(
  83.  
  84.         crossAxisCount: 2,
  85.         mainAxisSpacing: 4.0,
  86.         crossAxisSpacing: 4.0,
  87.  
  88.         children: getMenuItems()
  89.  
  90.       ),
  91.  
  92.       bottomNavigationBar: BottomAppBar(
  93.  
  94.         child: Row(
  95.  
  96.           mainAxisAlignment: MainAxisAlignment.spaceBetween,
  97.           mainAxisSize: MainAxisSize.max,
  98.  
  99.           children: <Widget>[
  100.  
  101.             IconButton(icon: Icon(Icons.cloud)),
  102.            
  103.             IconButton(icon: Icon(Icons.settings))
  104.  
  105.           ],
  106.  
  107.  
  108.         ),
  109.  
  110.       ),
  111.  
  112.     );
  113.  
  114.   }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement