From ab5de33d93c358532da880124127d5737f4226fb Mon Sep 17 00:00:00 2001 From: aslight0013 Date: Tue, 4 May 2021 18:06:17 +0600 Subject: [PATCH] done --- lib/main.dart | 11 ++++- lib/screens/dashboard/components/header.dart | 30 ++++++++---- .../dashboard/components/my_fiels.dart | 49 +++++++++++++++---- lib/screens/dashboard/dashboard_screen.dart | 19 ++++--- lib/screens/main/main_screen.dart | 18 ++++--- 5 files changed, 95 insertions(+), 32 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index ad222a1..bbd8dcc 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,7 +1,9 @@ import 'package:admin/constants.dart'; +import 'package:admin/controllers/MenuController.dart'; import 'package:admin/screens/main/main_screen.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'package:provider/provider.dart'; void main() { runApp(MyApp()); @@ -20,7 +22,14 @@ class MyApp extends StatelessWidget { .apply(bodyColor: Colors.white), canvasColor: secondaryColor, ), - home: MainScreen(), + home: MultiProvider( + providers: [ + ChangeNotifierProvider( + create: (context) => MenuController(), + ), + ], + child: MainScreen(), + ), ); } } diff --git a/lib/screens/dashboard/components/header.dart b/lib/screens/dashboard/components/header.dart index 890f10e..917801e 100644 --- a/lib/screens/dashboard/components/header.dart +++ b/lib/screens/dashboard/components/header.dart @@ -1,5 +1,8 @@ +import 'package:admin/controllers/MenuController.dart'; +import 'package:admin/responsive.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; +import 'package:provider/provider.dart'; import '../../../constants.dart'; @@ -12,11 +15,18 @@ class Header extends StatelessWidget { Widget build(BuildContext context) { return Row( children: [ - Text( - "Dashboard", - style: Theme.of(context).textTheme.headline6, - ), - Spacer(flex: 2), + if (!Responsive.isDesktop(context)) + IconButton( + icon: Icon(Icons.menu), + onPressed: context.read().controlMenu, + ), + if (!Responsive.isMobile(context)) + Text( + "Dashboard", + style: Theme.of(context).textTheme.headline6, + ), + if (!Responsive.isMobile(context)) + Spacer(flex: Responsive.isDesktop(context) ? 2 : 1), Expanded(child: SearchField()), ProfileCard() ], @@ -48,10 +58,12 @@ class ProfileCard extends StatelessWidget { "assets/images/profile_pic.png", height: 38, ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: defaultPadding / 2), - child: Text("Angelina Joli"), - ), + if (!Responsive.isMobile(context)) + Padding( + padding: + const EdgeInsets.symmetric(horizontal: defaultPadding / 2), + child: Text("Angelina Joli"), + ), Icon(Icons.keyboard_arrow_down), ], ), diff --git a/lib/screens/dashboard/components/my_fiels.dart b/lib/screens/dashboard/components/my_fiels.dart index 3e91a4e..772a163 100644 --- a/lib/screens/dashboard/components/my_fiels.dart +++ b/lib/screens/dashboard/components/my_fiels.dart @@ -1,4 +1,5 @@ import 'package:admin/models/MyFiles.dart'; +import 'package:admin/responsive.dart'; import 'package:flutter/material.dart'; import '../../../constants.dart'; @@ -11,6 +12,7 @@ class MyFiels extends StatelessWidget { @override Widget build(BuildContext context) { + final Size _size = MediaQuery.of(context).size; return Column( children: [ Row( @@ -24,7 +26,8 @@ class MyFiels extends StatelessWidget { style: TextButton.styleFrom( padding: EdgeInsets.symmetric( horizontal: defaultPadding * 1.5, - vertical: defaultPadding, + vertical: + defaultPadding / (Responsive.isMobile(context) ? 2 : 1), ), ), onPressed: () {}, @@ -34,18 +37,44 @@ class MyFiels extends StatelessWidget { ], ), SizedBox(height: defaultPadding), - GridView.builder( - shrinkWrap: true, - itemCount: demoMyFiels.length, - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 4, - crossAxisSpacing: defaultPadding, - childAspectRatio: 1.4, + Responsive( + mobile: FileInfoCardGridView( + crossAxisCount: _size.width < 650 ? 2 : 4, + childAspectRatio: _size.width < 650 ? 1.3 : 1, + ), + tablet: FileInfoCardGridView(), + desktop: FileInfoCardGridView( + childAspectRatio: _size.width < 1400 ? 1.1 : 1.4, ), - itemBuilder: (context, index) => - FileInfoCard(info: demoMyFiels[index]), ), ], ); } } + +class FileInfoCardGridView extends StatelessWidget { + const FileInfoCardGridView({ + Key key, + this.crossAxisCount = 4, + this.childAspectRatio = 1, + }) : super(key: key); + + final int crossAxisCount; + final double childAspectRatio; + + @override + Widget build(BuildContext context) { + return GridView.builder( + physics: NeverScrollableScrollPhysics(), + shrinkWrap: true, + itemCount: demoMyFiels.length, + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: crossAxisCount, + crossAxisSpacing: defaultPadding, + mainAxisSpacing: defaultPadding, + childAspectRatio: childAspectRatio, + ), + itemBuilder: (context, index) => FileInfoCard(info: demoMyFiels[index]), + ); + } +} diff --git a/lib/screens/dashboard/dashboard_screen.dart b/lib/screens/dashboard/dashboard_screen.dart index 7b4a3ec..093745a 100644 --- a/lib/screens/dashboard/dashboard_screen.dart +++ b/lib/screens/dashboard/dashboard_screen.dart @@ -1,3 +1,4 @@ +import 'package:admin/responsive.dart'; import 'package:flutter/material.dart'; import '../../constants.dart'; @@ -25,15 +26,21 @@ class DashboardScreen extends StatelessWidget { children: [ MyFiels(), SizedBox(height: defaultPadding), - RecentFiles() + RecentFiles(), + if (Responsive.isMobile(context)) + SizedBox(height: defaultPadding), + if (Responsive.isMobile(context)) StarageDetails(), ], ), ), - SizedBox(width: defaultPadding), - Expanded( - flex: 2, - child: StarageDetails(), - ), + if (!Responsive.isMobile(context)) + SizedBox(width: defaultPadding), + // On Mobile means if the screen is less than 850 we dont want to show it + if (!Responsive.isMobile(context)) + Expanded( + flex: 2, + child: StarageDetails(), + ), ], ) ], diff --git a/lib/screens/main/main_screen.dart b/lib/screens/main/main_screen.dart index 709c740..a8a6002 100644 --- a/lib/screens/main/main_screen.dart +++ b/lib/screens/main/main_screen.dart @@ -1,6 +1,8 @@ +import 'package:admin/controllers/MenuController.dart'; +import 'package:admin/responsive.dart'; import 'package:admin/screens/dashboard/dashboard_screen.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_svg/svg.dart'; +import 'package:provider/provider.dart'; import 'components/side_menu.dart'; @@ -8,15 +10,19 @@ class MainScreen extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( + key: context.read().scaffoldKey, + drawer: SideMenu(), body: SafeArea( child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Expanded( - // default flex = 1 - // and it takes 1/6 part of the screen - child: SideMenu(), - ), + // We want this side menu only for large screen + if (Responsive.isDesktop(context)) + Expanded( + // default flex = 1 + // and it takes 1/6 part of the screen + child: SideMenu(), + ), Expanded( // It takes 5/6 part of the screen flex: 5,