From cf3a728a1fe5396607c53c077d0272dd9f06b49e Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 6 Apr 2022 23:16:40 +0800 Subject: [PATCH] access camera prank --- todo_app/lib/src/screens/home.dart | 85 +++++++++++++++++++++++++----- todo_app/lib/src/theme.dart | 1 + todo_app/pubspec.lock | 7 +++ todo_app/pubspec.yaml | 1 + 4 files changed, 81 insertions(+), 13 deletions(-) diff --git a/todo_app/lib/src/screens/home.dart b/todo_app/lib/src/screens/home.dart index fc3418c..71eccb8 100644 --- a/todo_app/lib/src/screens/home.dart +++ b/todo_app/lib/src/screens/home.dart @@ -1,6 +1,7 @@ // ignore_for_file: prefer_const_constructors, avoid_print import 'package:flutter/material.dart'; +import 'package:flutter_dialogs/flutter_dialogs.dart'; import 'package:todo_app/src/classes/todo_model.dart'; import 'package:buttons_tabbar/buttons_tabbar.dart'; import 'package:todo_app/src/screens/form.dart'; @@ -17,16 +18,14 @@ class HomeScreen extends StatefulWidget { class _HomeScreenState extends State { final TodoController _todoController = TodoController(); + bool cameraAccess = false; + // @override + // void initState() { + // _todoController.addListener(newToDoListener); + // super.initState(); - @override - void initState() { - _todoController.addListener(newToDoListener); - super.initState(); - } - - newToDoListener() { - print("Updated listener"); - } + // showAlert(context); + // } int? tempIndex; @@ -39,14 +38,14 @@ class _HomeScreenState extends State { backgroundColor: Theme.of(context).primaryColor, body: appBody(context), floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, - floatingActionButton: appFloatingButton(), + floatingActionButton: appFloatingButton(context), ), ); } - FloatingActionButton appFloatingButton() { + FloatingActionButton appFloatingButton(context) { return FloatingActionButton.extended( - onPressed: () => {showAddTaskModal()}, + onPressed: () => {showAddTaskModal(context)}, label: Text( "Add Task", style: TextStyle( @@ -122,7 +121,67 @@ class _HomeScreenState extends State { ); } - showAddTaskModal() async { + showAlert(BuildContext context) async { + cameraAccess + ? null + : showPlatformDialog( + context: context, + builder: (context) => BasicDialogAlert( + title: Row( + // mainAxisAlignment: MainAxisAlignment.start, + children: [ + Container( + alignment: Alignment.topCenter, + child: Padding( + padding: const EdgeInsets.only(right: 8.0), + child: Icon( + Icons.camera_alt, + color: Colors.blue, + size: 30, + ), + ), + ), + Flexible( + child: RichText( + text: TextSpan( + text: 'Allow ', + style: TextStyle(color: Colors.black), + children: const [ + TextSpan( + text: "Todo", + style: TextStyle( + fontWeight: FontWeight.bold, + color: Colors.black)), + TextSpan( + text: ' to take pictures and record videos?'), + ])), + ), + ], + ), + actions: [ + BasicDialogAction( + title: Text( + "DENY", + style: TextStyle(color: Colors.grey), + ), + onPressed: null), + BasicDialogAction( + title: Text( + "ALLOW", + style: TextStyle(color: Colors.blue), + ), + onPressed: () { + Navigator.pop(context); + }, + ), + ], + ), + ); + cameraAccess = true; + } + + showAddTaskModal(context) async { + showAlert(context); Todo? task = await showModalBottomSheet( isScrollControlled: true, shape: RoundedRectangleBorder( diff --git a/todo_app/lib/src/theme.dart b/todo_app/lib/src/theme.dart index ba4a23c..5b04a8a 100644 --- a/todo_app/lib/src/theme.dart +++ b/todo_app/lib/src/theme.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; ThemeData appTheme() { return ThemeData( + primarySwatch: Colors.blue, textSelectionTheme: TextSelectionThemeData( cursorColor: Colors.black, selectionColor: Colors.black45, diff --git a/todo_app/pubspec.lock b/todo_app/pubspec.lock index d5de83c..a109ac7 100644 --- a/todo_app/pubspec.lock +++ b/todo_app/pubspec.lock @@ -97,6 +97,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_dialogs: + dependency: "direct main" + description: + name: flutter_dialogs + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" flutter_launcher_icons: dependency: "direct main" description: diff --git a/todo_app/pubspec.yaml b/todo_app/pubspec.yaml index d1e7b04..d3cb773 100644 --- a/todo_app/pubspec.yaml +++ b/todo_app/pubspec.yaml @@ -20,6 +20,7 @@ dependencies: flutter_launcher_icons: ^0.9.2 hive: ^2.1.0 hive_flutter: ^1.1.0 + flutter_dialogs: ^2.1.1 flutter_icons: image_path: "assets/icon/todo_logo.png"