Skip to content

Commit

Permalink
refactor: finishing touches
Browse files Browse the repository at this point in the history
  • Loading branch information
codewithJosh committed Nov 18, 2022
1 parent c0c3ee6 commit e36a387
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 140 deletions.
3 changes: 2 additions & 1 deletion lib/create_update_screen.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import 'dart:io';

import 'package:flutter/material.dart';

class CreateUpdateScreen extends StatefulWidget {
final File uri;

const CreateUpdateScreen({Key? key, required this.uri}) : super(key: key);

@override
State<CreateUpdateScreen> createState() => _CreateUpdateScreenState();
}

class _CreateUpdateScreenState extends State<CreateUpdateScreen> {

@override
Widget build(BuildContext context) {
return Container();
Expand Down
58 changes: 27 additions & 31 deletions lib/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,37 +309,33 @@ buildFlutterToast(final msg, final color, {isLong = false}) =>
fontSize: 16.0);

initTitle1() => Row(
children: const <Widget>[

Text(
'News',
style: TextStyle(
fontSize: 22,
color: Colors.white,
fontFamily: 'Tahoma',
),
),

Text(
'EXPOSÉ',
style: TextStyle(
fontSize: 22,
color: colorFulvous,
fontFamily: 'Tahoma',
),
)
],
);
children: const <Widget>[
Text(
'News',
style: TextStyle(
fontSize: 22,
color: Colors.white,
fontFamily: 'Tahoma',
),
),
Text(
'EXPOSÉ',
style: TextStyle(
fontSize: 22,
color: colorFulvous,
fontFamily: 'Tahoma',
),
)
],
);

buildCircularProgress() => Container(
alignment: Alignment.center,
child: const SizedBox(
height: 100.0,
width: 100.0,
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(
colorPhilippineOrange
alignment: Alignment.center,
child: const SizedBox(
height: 100.0,
width: 100.0,
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(colorPhilippineOrange),
),
),
),
),
);
);
187 changes: 82 additions & 105 deletions lib/home_screen.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:image_picker/image_picker.dart';
import 'package:news_expose_2k21/create_update_screen.dart';
import 'package:news_expose_2k21/functions.dart';

import 'models/user_model.dart';

class HomeScreen extends StatefulWidget {
Expand All @@ -15,169 +17,144 @@ class HomeScreen extends StatefulWidget {
}

class _HomeScreenState extends State<HomeScreen> {

late File _uri;

_initAppBar() => AppBar(
systemOverlayStyle: SystemUiOverlayStyle.light,
backgroundColor: colorChineseBlack,
toolbarHeight: 75.0,

flexibleSpace: SafeArea(
child: Container(
alignment: Alignment.center,
decoration: const BoxDecoration(
gradient: linearAppBar,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[

Container(
margin: const EdgeInsets.only(left: 20.0),
child: SvgPicture.string(
createLogoUIButton,
allowDrawingOutsideViewBox: true,
fit: BoxFit.fill,
),
systemOverlayStyle: SystemUiOverlayStyle.light,
backgroundColor: colorChineseBlack,
toolbarHeight: 75.0,
flexibleSpace: SafeArea(
child: Container(
alignment: Alignment.center,
decoration: const BoxDecoration(
gradient: linearAppBar,
),

initTitle1(),

Container(
margin: const EdgeInsets.only(right: 20.0),
child: SvgPicture.string(
createDrawerUIButton,
allowDrawingOutsideViewBox: true,
fit: BoxFit.fill,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
margin: const EdgeInsets.only(left: 20.0),
child: SvgPicture.string(
createLogoUIButton,
allowDrawingOutsideViewBox: true,
fit: BoxFit.fill,
),
),
initTitle1(),
Container(
margin: const EdgeInsets.only(right: 20.0),
child: SvgPicture.string(
createDrawerUIButton,
allowDrawingOutsideViewBox: true,
fit: BoxFit.fill,
),
),
],
),

],
),
),
),
),
);
);

_buildGetImage(final context) => showModalBottomSheet(
context: context,
builder: (context) => Container(
context: context,
builder: (context) => Container(
decoration: const BoxDecoration(
gradient: linearAppBar,
),
height: 120,
child: Column(
children: <Widget>[

_initListTile(context, 'Capture Image with Camera'),

_initListTile(context, 'Select Image from Gallery')

],
),
)
);
));

_initListTile(final context, final text) => ListTile(

leading: SizedBox(
width: 30.0,
height: 25.0,
child: SvgPicture.string(
text.contains('Capture Image with Camera')
? createCameraUIButton
: createGalleryUIButton,
allowDrawingOutsideViewBox: true,
fit: BoxFit.fill,
),
),

title: Text(
text,
style: const TextStyle(
color: Colors.white,
),
),

onTap: () async {
final image = await ImagePicker().pickImage(
source: text.contains('Capture Image with Camera')
? ImageSource.camera
: ImageSource.gallery
leading: SizedBox(
width: 30.0,
height: 25.0,
child: SvgPicture.string(
text.contains('Capture Image with Camera')
? createCameraUIButton
: createGalleryUIButton,
allowDrawingOutsideViewBox: true,
fit: BoxFit.fill,
),
),
title: Text(
text,
style: const TextStyle(
color: Colors.white,
),
),
onTap: () async {
final image = await ImagePicker().pickImage(
source: text.contains('Capture Image with Camera')
? ImageSource.camera
: ImageSource.gallery);
Navigator.of(context).pop();
setState(() {
_uri = File(image!.path);
});
_onCreateUpdate(context);
},
);
Navigator.of(context).pop();
setState(() {
_uri = File(image!.path);
});
_onCreateUpdate(context);
},
);

_onCreateUpdate(final context) {

final route = MaterialPageRoute(
builder: (context) => CreateUpdateScreen(
uri: _uri
)
);
final route =
MaterialPageRoute(builder: (context) => CreateUpdateScreen(uri: _uri));
Navigator.of(context).push(route);
}

@override
Widget build(BuildContext context) {
return Scaffold(

appBar: _initAppBar(),

body: Stack(
children: <Widget>[

Container(
decoration: const BoxDecoration(
color: colorChineseBlack,
),
),

SafeArea(
child: Stack(
children: <Widget>[

FutureBuilder(
future: users.doc(userId).get(),
builder: (context, dataSnapshot) {
if(!dataSnapshot.hasData) {
if (!dataSnapshot.hasData) {
return buildCircularProgress();
}

final user = User.fromDocument(dataSnapshot.data);

return user.userIsAdmin == true
? Container(
alignment: Alignment.bottomRight,
padding: const EdgeInsets.only(right: 25.0, bottom: 25.0),
child: GestureDetector(
onTap: () => _buildGetImage(context),
child: SizedBox(
width: 75.0,
height: 75.0,
child: SvgPicture.string(
createCreateUpdateUIButton,
allowDrawingOutsideViewBox: true,
fit: BoxFit.fill,
alignment: Alignment.bottomRight,
padding: const EdgeInsets.only(
right: 25.0, bottom: 25.0),
child: GestureDetector(
onTap: () => _buildGetImage(context),
child: SizedBox(
width: 75.0,
height: 75.0,
child: SvgPicture.string(
createCreateUpdateUIButton,
allowDrawingOutsideViewBox: true,
fit: BoxFit.fill,
),
),
),
),
)
)
: Container();
}
),

}),
],
),
),
],
),

);
}
}
3 changes: 0 additions & 3 deletions lib/models/user_model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


class User {
final String? buildNumber;
final String? userBio;
Expand All @@ -20,7 +18,6 @@ class User {
});

factory User.fromDocument(final documentSnapshot) {

return User(
buildNumber: documentSnapshot['build_number'],
userBio: documentSnapshot['user_bio'],
Expand Down

0 comments on commit e36a387

Please sign in to comment.