You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have used a list view and checkboc in the screen of a navbar but the screen is invisible and black while it working marking the box true and uploading image too . here's the code
import 'package:op_checklist/consts/consts.dart';
import 'package:op_checklist/views/completedtasks_screen/completedtasks_screen.dart';
import 'package:op_checklist/views/home_screen/home_screen.dart';
import 'package:op_checklist/views/pendingtasks_screen/pendingtasks_screen.dart';
import 'package:op_checklist/views/profile_screen/profile_screen.dart';
import 'package:get/get.dart';
import '../../controller/home_controller.dart';
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Select Topic Area
Bug
Body
I have used a list view and checkboc in the screen of a navbar but the screen is invisible and black while it working marking the box true and uploading image too . here's the code
import 'package:op_checklist/consts/consts.dart';
import 'package:op_checklist/views/completedtasks_screen/completedtasks_screen.dart';
import 'package:op_checklist/views/home_screen/home_screen.dart';
import 'package:op_checklist/views/pendingtasks_screen/pendingtasks_screen.dart';
import 'package:op_checklist/views/profile_screen/profile_screen.dart';
import 'package:get/get.dart';
import '../../controller/home_controller.dart';
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@OverRide
State createState() => _HomeState();
}
class _HomeState extends State {
var navbarItem = [
BottomNavigationBarItem(icon: Image.asset(icHome, width: 26), label: home),
BottomNavigationBarItem(
icon: Image.asset(icCompletedTasks, width: 26), label: completedTask),
BottomNavigationBarItem(
icon: Image.asset(icPendingTasks, width: 26), label: pendingTasks),
BottomNavigationBarItem(
icon: ColorFiltered(
colorFilter: const ColorFilter.mode(Colors.orange, BlendMode.srcIn),
child: Image.asset(icProfile, width: 26),
),
label: account,
),
];
var navBody = [
const HomeScreen(),
const CompletedTasksScreen(tasks:[]),
const PendingTasksScreen(),
const ProfileScreen(),
];
@OverRide
Widget build(BuildContext context) {
var controller = Get.put(HomeController());
return Scaffold(
body: Column(
children: [
Obx(() => Expanded(
child: navBody.elementAt(controller.currentNavIndex.value))),
],
),
bottomNavigationBar: Obx(
() => BottomNavigationBar(
currentIndex: controller.currentNavIndex.value,
selectedItemColor: orange,
selectedLabelStyle: const TextStyle(fontFamily: semibold),
type: BottomNavigationBarType.fixed,
backgroundColor: whiteColor,
items: navbarItem,
onTap: (value) {
controller.currentNavIndex.value = value;
}),
),
);
}
}
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import '../../consts/colors.dart';
class Task {
String name;
bool isCompleted;
File? image;
Task({required this.name, this.isCompleted = false, this.image});
}
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);
@OverRide
HomeScreenState createState() => HomeScreenState();
}
class HomeScreenState extends State {
List tasks = [
Task(name: "Task 1"),
Task(name: "Task 2"),
Task(name: "Task 3"),
Task(name: "Task 4"),
Task(name: "Task 5"),
Task(name: "Task 6"),
Task(name: "Task 7"),
Task(name: "Task 8"),
Task(name: "Task 9"),
];
List completedTasks = [];
void toggleTask(int index) async {
if (tasks[index].image != null) {
setState(() {
tasks[index].isCompleted = !tasks[index].isCompleted;
if (tasks[index].isCompleted) {
completedTasks.add(tasks[index]);
} else {
completedTasks.remove(tasks[index]);
}
});
} else {
await _showImageUploadDialog(index);
}
}
Future _showImageUploadDialog(int index) async {
final picker = ImagePicker();
await showDialog(
context: context,
builder: (BuildContext context) {
return Container(decoration:const BoxDecoration(color: lightGrey),
child: AlertDialog(
title: const Text('Upload Image'),
content: SingleChildScrollView(
child: ListBody(
children: [
ListTile(tileColor: Colors.grey,
leading: const Icon(Icons.camera_alt),
title: const Text('Take a Photo'),
onTap: () async {
Navigator.pop(context);
final image = await picker.pickImage(
source: ImageSource.camera,
);
if (image != null) {
setState(() {
tasks[index].image = File(image.path);
});
}
},
),
ListTile(
leading: const Icon(Icons.photo_library),
title: const Text('Choose from Gallery'),
onTap: () async {
Navigator.pop(context);
final image = await picker.pickImage(
source: ImageSource.gallery,
);
if (image != null) {
setState(() {
tasks[index].image = File(image.path);
});
}
},
),
],
),
),
),
);
},
);
}
@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Checklist'),
),
body: Container(
child: ListView.builder(
itemCount: tasks.length,
itemBuilder: (context, index) {
final task = tasks[index];
return ListTile(
title: Text(task.name),
trailing: Checkbox(
value: task.isCompleted,
onChanged: (value) => toggleTask(index),
),
leading: task.image != null
? Image.file(
task.image!,
width: 50,
height: 50,
fit: BoxFit.cover,
)
: IconButton(
icon: const Icon(Icons.camera_alt),
onPressed: () => _showImageUploadDialog(index),
),
);
},
),
),
);
}
}
Beta Was this translation helpful? Give feedback.
All reactions