From 59f4cc099e8555834ecbc9bb892f9f147caaae3d Mon Sep 17 00:00:00 2001 From: AYM1607 Date: Tue, 2 Apr 2019 06:08:11 -0600 Subject: [PATCH] Moved repeated text styles to utils, Finished the UI for the Add image screen --- lib/src/blocs/new_image_bloc.dart | 15 +++- lib/src/screens/new_image_screen.dart | 90 ++++++++++++++++++- lib/src/screens/new_task_screen.dart | 18 +--- lib/src/utils.dart | 11 +++ lib/src/widgets/custom_dropdown.dart | 2 + .../widgets/gradient_touchable_container.dart | 2 + 6 files changed, 122 insertions(+), 16 deletions(-) diff --git a/lib/src/blocs/new_image_bloc.dart b/lib/src/blocs/new_image_bloc.dart index ab380b7..6945b6c 100644 --- a/lib/src/blocs/new_image_bloc.dart +++ b/lib/src/blocs/new_image_bloc.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:io'; import 'package:rxdart/rxdart.dart'; @@ -7,4 +8,16 @@ import '../models/user_model.dart'; import '../resources/authService.dart'; import '../resources/firestore_provider.dart'; -class NewImageBloc {} +class NewImageBloc { + final _picture = BehaviorSubject(); + + //Stream getters. + Observable get picture => _picture.stream; + + //Sink getters. + Function(File) get addPicture => _picture.sink.add; + + void dispose() { + _picture.close(); + } +} diff --git a/lib/src/screens/new_image_screen.dart b/lib/src/screens/new_image_screen.dart index fcb027d..71fd5bc 100644 --- a/lib/src/screens/new_image_screen.dart +++ b/lib/src/screens/new_image_screen.dart @@ -1,7 +1,14 @@ -import 'package:flutter/material.dart'; +import 'dart:async'; +import 'dart:io'; +import 'package:flutter/material.dart'; +import 'package:image_picker/image_picker.dart'; + +import '../utils.dart'; import '../blocs/new_image_bloc.dart'; import '../widgets/custom_app_bar.dart'; +import '../widgets/custom_dropdown.dart'; +import '../widgets/gradient_touchable_container.dart'; class NewImageScreen extends StatefulWidget { _NewImageScreenState createState() => _NewImageScreenState(); @@ -15,6 +22,87 @@ class _NewImageScreenState extends State { appBar: CustomAppBar( title: 'Add image', ), + body: Padding( + padding: const EdgeInsets.only(left: 10.0, right: 10.0, top: 10.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + SizedBox( + height: 10, + ), + Center( + child: GestureDetector( + onTap: () => takePicture(), + child: Container( + height: 300, + color: Theme.of(context).cardColor, + child: StreamBuilder( + stream: bloc.picture, + builder: (BuildContext context, AsyncSnapshot snap) { + if (!snap.hasData) { + return Center( + child: Text( + 'Tap to take picture', + style: kSmallTextStyle, + ), + ); + } + return Image.file( + snap.data, + fit: BoxFit.cover, + ); + }, + ), + ), + ), + ), + SizedBox( + height: 10, + ), + buildEventSection(), + SizedBox( + height: 10, + ), + GradientTouchableContainer( + height: 40, + width: 350, + radius: 8, + onTap: () {}, + child: Text( + 'Submit', + style: kSmallTextStyle, + ), + ), + ], + ), + ), ); } + + Future takePicture() async { + final File imgFile = await ImagePicker.pickImage( + source: ImageSource.camera, + ); + bloc.addPicture(imgFile); + } + + Widget buildEventSection() { + return Row( + children: [ + Text( + 'Event', + style: kBigTextStyle, + ), + Spacer(), + CustomDropdownButton( + width: 200, + ), + ], + ); + } + + void dispose() { + bloc.dispose(); + super.dispose(); + } } diff --git a/lib/src/screens/new_task_screen.dart b/lib/src/screens/new_task_screen.dart index 503c5d2..63c42ab 100644 --- a/lib/src/screens/new_task_screen.dart +++ b/lib/src/screens/new_task_screen.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; +import '../utils.dart'; import '../blocs/new_task_bloc.dart'; import '../models/user_model.dart'; import '../widgets/custom_app_bar.dart'; @@ -14,17 +15,6 @@ class NewTaskScreen extends StatefulWidget { } class _NewTaskScreenState extends State { - static const kLabelStyle = TextStyle( - color: Colors.white, - fontSize: 24, - fontWeight: FontWeight.w600, - ); - static const kButtonStyle = TextStyle( - color: Colors.white, - fontSize: 16, - fontWeight: FontWeight.w500, - ); - final NewTaskBloc bloc = NewTaskBloc(); String dropdownValue; @@ -68,7 +58,7 @@ class _NewTaskScreenState extends State { onTap: () => onSubmit(context, bloc), child: Text( 'Submit', - style: kButtonStyle, + style: kSmallTextStyle, ), ), ], @@ -84,7 +74,7 @@ class _NewTaskScreenState extends State { children: [ Text( 'Event', - style: kLabelStyle, + style: kBigTextStyle, ), Spacer(), CustomDropdownButton( @@ -111,7 +101,7 @@ class _NewTaskScreenState extends State { children: [ Text( 'Priority', - style: kLabelStyle, + style: kBigTextStyle, ), Spacer(), PrioritySelector( diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 206b0d9..0952551 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -5,6 +5,17 @@ const kLowPriorityColor = Color(0xFF06AD12); const kMediumPriorityColor = Color(0xFFF6A93B); const kHighPriorityColor = Color(0xFFF42850); +const kBigTextStyle = TextStyle( + color: Colors.white, + fontSize: 24, + fontWeight: FontWeight.w600, +); +const kSmallTextStyle = TextStyle( + color: Colors.white, + fontSize: 16, + fontWeight: FontWeight.w500, +); + Color getColorFromPriority(TaskPriority priority) { switch (priority) { case TaskPriority.low: diff --git a/lib/src/widgets/custom_dropdown.dart b/lib/src/widgets/custom_dropdown.dart index 65b33e9..b283249 100644 --- a/lib/src/widgets/custom_dropdown.dart +++ b/lib/src/widgets/custom_dropdown.dart @@ -17,6 +17,8 @@ const EdgeInsets _kAlignedMenuMargin = EdgeInsets.zero; const EdgeInsetsGeometry _kUnalignedMenuMargin = EdgeInsetsDirectional.only(start: 16.0, end: 24.0); +//TODO: Refactor to allow expansion if no width is provided. + class _DropdownMenuPainter extends CustomPainter { _DropdownMenuPainter({ this.color, diff --git a/lib/src/widgets/gradient_touchable_container.dart b/lib/src/widgets/gradient_touchable_container.dart index aa93f7d..cf64e7d 100644 --- a/lib/src/widgets/gradient_touchable_container.dart +++ b/lib/src/widgets/gradient_touchable_container.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; +//TODO: Refactor to allow expansion if no width is provided. + class GradientTouchableContainer extends StatelessWidget { /// The border radius of the button. final double radius;