Skip to content

Commit

Permalink
chore: Formated code and resolved the issue for the screen rotation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhalakupadhyay committed Jul 27, 2024
1 parent ab6c567 commit f99ef67
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 46 deletions.
12 changes: 8 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
import 'package:badgemagic/providers/cardsprovider.dart';
import 'package:badgemagic/providers/drawbadge_provider.dart';
import 'package:badgemagic/providers/getitlocator.dart';
import 'package:badgemagic/providers/imageprovider.dart';
import 'package:badgemagic/view/draw_badge_screen.dart';
import 'package:badgemagic/view/homescreen.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';

void main() {
setupLocator();
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
.then((_) {
runApp(MultiProvider(
providers: [
ChangeNotifierProvider<CardProvider>(
create: (context) => getIt<CardProvider>()),
ChangeNotifierProvider<InlineImageProvider>(
create: (context) => getIt<InlineImageProvider>()),
ChangeNotifierProvider<DrawBadgeProvider>(
create: (context) => DrawBadgeProvider()),
],
child: const MyApp(),
));
});
}
Future<void> _startImageCaching() async {
InlineImageProvider inlineImageProvider = getIt<InlineImageProvider>();
await inlineImageProvider.generateImageCache();
}

class MyApp extends StatelessWidget {
const MyApp({super.key});


@override
Widget build(BuildContext context) {
Expand Down
35 changes: 35 additions & 0 deletions lib/providers/drawbadge_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';

class DrawBadgeProvider extends ChangeNotifier{

//List that contains the state of each cell of the badge
List<List<bool>> grid =
List.generate(11, (i) => List.generate(44, (j) => false));

//function to update the state of the cell
void updateGrid(int row, int col) {
grid[row][col] = isDrawing;
notifyListeners();
}

//function to reset the state of the cell
void resetGrid() {
grid = List.generate(11, (i) => List.generate(44, (j) => false));
notifyListeners();
}

//function to get the state of the cell
List<List<bool>> getGrid() => grid;

//boolean variable to check for isDrawing on Draw badge screen
bool isDrawing = true;

//function to toggle the isDrawing variable
void toggleIsDrawing(bool drawing) {
isDrawing = drawing;
notifyListeners();
}

//function to get the isDrawing variable
bool getIsDrawing() => isDrawing;
}
2 changes: 2 additions & 0 deletions lib/providers/getitlocator.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:badgemagic/providers/cardsprovider.dart';
import 'package:badgemagic/providers/drawbadge_provider.dart';
import 'package:badgemagic/providers/imageprovider.dart';
import 'package:get_it/get_it.dart';

Expand All @@ -7,4 +8,5 @@ final GetIt getIt = GetIt.instance;
void setupLocator() {
getIt.registerLazySingleton<CardProvider>(() => CardProvider());
getIt.registerLazySingleton<InlineImageProvider>(() => InlineImageProvider());
getIt.registerLazySingleton<DrawBadgeProvider>(() => DrawBadgeProvider());
}
30 changes: 0 additions & 30 deletions lib/providers/imageprovider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,10 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class InlineImageProvider extends ChangeNotifier {
//List that contains the state of each cell of the badge
List<List<bool>> grid =
List.generate(11, (i) => List.generate(44, (j) => false));

//function to update the state of the cell
void updateGrid(int row, int col) {
grid[row][col] = isDrawing;
notifyListeners();
}

//function to reset the state of the cell
void resetGrid() {
grid = List.generate(11, (i) => List.generate(44, (j) => false));
notifyListeners();
}

//function to get the state of the cell
List<List<bool>> getGrid() => grid;

//list of vectors
List<String> vectors = [];

//boolean variable to check for isDrawing on Draw badge screen
bool isDrawing = true;

//function to toggle the isDrawing variable
void toggleIsDrawing(bool drawing) {
isDrawing = drawing;
notifyListeners();
}

//function to get the isDrawing variable
bool getIsDrawing() => isDrawing;

//initializes the list of vectors
//uses the AssetManifest class to load the list of assets
Future<void> initVectors() async {
Expand Down
26 changes: 20 additions & 6 deletions lib/view/draw_badge_screen.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:badgemagic/providers/drawbadge_provider.dart';
import 'package:badgemagic/providers/imageprovider.dart';
import 'package:badgemagic/view/widgets/navigation_drawer.dart';
import 'package:badgemagic/virtualbadge/view/draw_badge.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get_it/get_it.dart';
import 'package:provider/provider.dart';

class DrawBadge extends StatefulWidget {
Expand All @@ -14,20 +16,32 @@ class DrawBadge extends StatefulWidget {
}

class _DrawBadgeState extends State<DrawBadge> {
DrawBadgeProvider cellStateToggle = GetIt.instance<DrawBadgeProvider>();

@override
void dispose() {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
super.dispose();
void initState() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
]);
super.initState();
}

@override
Widget build(BuildContext context) {
InlineImageProvider drawToggle = Provider.of<InlineImageProvider>(context);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
void dispose() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
cellStateToggle.resetGrid();
super.dispose();
}

@override
Widget build(BuildContext context) {
DrawBadgeProvider drawToggle = Provider.of<DrawBadgeProvider>(context);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
return Scaffold(
appBar: AppBar(
leading: Builder(builder: (context) {
Expand Down
28 changes: 26 additions & 2 deletions lib/view/homescreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:badgemagic/view/widgets/vectorview.dart';
import 'package:badgemagic/virtualbadge/view/badge_home_view.dart';
import 'package:extended_text_field/extended_text_field.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get_it/get_it.dart';
import 'package:provider/provider.dart';
Expand All @@ -30,19 +31,42 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
InlineImageProvider inlineImageProvider =
GetIt.instance<InlineImageProvider>();
Converters converters = Converters();

bool isCacheInitialized = false;
bool isPrefixIconClicked = false;

@override
void initState() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
_startImageCaching();
super.initState();

_tabController = TabController(length: 3, vsync: this);
}

@override
void dispose() {
_tabController.dispose();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
super.dispose();
}



Future<void> _startImageCaching() async {
await inlineImageProvider.generateImageCache();
if(!isCacheInitialized)
{
await inlineImageProvider.generateImageCache();
setState(() {
isCacheInitialized = true;
});
}
}

@override
Expand Down
1 change: 0 additions & 1 deletion lib/view/widgets/navigation_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class BMDrawer extends StatelessWidget {
},
),
ListTile(
//Add Icons from assets
leading: const Icon(Icons.draw_outlined),
title: const Text('Draw Clipart'),
onTap: () {
Expand Down
3 changes: 2 additions & 1 deletion lib/virtualbadge/view/draw_badge.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:badgemagic/providers/drawbadge_provider.dart';
import 'package:badgemagic/providers/imageprovider.dart';
import 'package:badgemagic/virtualbadge/widgets/badge_widget.dart';
import 'package:flutter/material.dart';
Expand All @@ -11,7 +12,7 @@ class BMBadge extends StatefulWidget {
}

class _BMBadgeState extends State<BMBadge> {
InlineImageProvider cellStateToggle = GetIt.instance<InlineImageProvider>();
DrawBadgeProvider cellStateToggle = GetIt.instance<DrawBadgeProvider>();
static const int rows = 11;
static const int cols = 44;

Expand Down
6 changes: 4 additions & 2 deletions lib/virtualbadge/widgets/badge_widget.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:badgemagic/providers/drawbadge_provider.dart';
import 'package:badgemagic/providers/imageprovider.dart';
import 'package:badgemagic/view/draw_badge_screen.dart';
import 'package:badgemagic/virtualbadge/view/cell.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
Expand All @@ -16,8 +18,8 @@ class BadgeWidget extends StatefulWidget {
class _BadgeWidgetState extends State<BadgeWidget> {
@override
Widget build(BuildContext context) {
InlineImageProvider cellStateToggle =
Provider.of<InlineImageProvider>(context);
DrawBadgeProvider cellStateToggle =
Provider.of<DrawBadgeProvider>(context);
return CustomPaint(
size: const Size(400, 480),
painter: BadgePainter(grid: cellStateToggle.getGrid()),
Expand Down

0 comments on commit f99ef67

Please sign in to comment.