Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import './NewProjectSheet.dart';
- import 'package:path_provider/path_provider.dart';
- import 'dart:io';
- import './MenuItem.dart';
- import './../../../core/Project.dart';
- class HomePage extends StatefulWidget{
- @override
- _HomePageState createState() => _HomePageState();
- }
- class _HomePageState extends State<HomePage> {
- Directory _dir;
- void _showModalSheet() {
- showModalBottomSheet(
- context: context,
- builder: (builder) {
- return NewProjectSheet();
- }
- );
- }
- @override
- void initState() {
- super.initState();
- getApplicationDocumentsDirectory().then((dir){
- setState(() {
- _dir = dir;
- });
- });
- }
- List<Widget> getMenuItems(){
- print("getting items!");
- if(_dir != null)
- return _dir.listSync()
- .where((f) => f is File)
- .map((f) => f as File)
- .where((f) => f.path.endsWith(".pfile.json"))
- .map((f) => f.readAsStringSync())
- .map((s) => MenuItem(Project.fromJSonString(s)))
- .toList();
- print("was null");
- return [];
- }
- @override
- Widget build(BuildContext context){
- return Scaffold(
- floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
- floatingActionButton: FloatingActionButton(
- child: Icon(Icons.add),
- onPressed: _showModalSheet,
- ),
- body: GridView.count(
- crossAxisCount: 2,
- mainAxisSpacing: 4.0,
- crossAxisSpacing: 4.0,
- children: getMenuItems()
- ),
- bottomNavigationBar: BottomAppBar(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- mainAxisSize: MainAxisSize.max,
- children: <Widget>[
- IconButton(icon: Icon(Icons.cloud)),
- IconButton(icon: Icon(Icons.settings))
- ],
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement