Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help fix my dart / flutter app. it is supposed to look just like the picture. I keep getting an error for downloading the

Please help fix my dart/flutter app. it is supposed to look just like the picture. I keep getting an error for downloading the uri shared prefernces. The code is provided below please edit it to get it to look like the pictures. Thank you so much. import 'package:flutter/material.dart';
import 'dart:math';
import 'package:shared_preferences/shared_preferences.dart';
void main(){
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context){
return MaterialApp(
title: 'Random Student Picker',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: RandomStudentPicker(),
);
}
}
class RandomStudentPicker extends StatefulWidget {
@override
_RandomStudentPickerState createState()=>_RandomStudentPickerState();
}
class _RandomStudentPickerState extends State {
final List students =[];
final List hiddenStudents =[];
String selectedStudent ='';
@override
void initState(){
super.initState();
_loadStudents();
}
Future _loadStudents() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
setState((){
students.addAll(prefs.getStringList('students')??[]);
hiddenStudents.addAll(prefs.getStringList('hiddenStudents')??[]);
});
}
Future _saveStudents() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setStringList('students', students);
await prefs.setStringList('hiddenStudents', hiddenStudents);
}
void pickRandomStudent(){
setState((){
final List visibleStudents =
students.where((student)=>!hiddenStudents.contains(student)).toList();
if (visibleStudents.isNotEmpty){
final Random random = Random();
selectedStudent = visibleStudents[random.nextInt(visibleStudents.length)];
print('Selected Student: $selectedStudent');
} else {
print('No visible students available');
}
});
}
void toggleVisibility(String student){
setState((){
if (hiddenStudents.contains(student)){
hiddenStudents.remove(student);
} else {
hiddenStudents.add(student);
}
_saveStudents();
});
}
void addName(String name){
setState((){
students.add(name);
_saveStudents();
});
}
void deleteStudent(String student){
setState((){
students.remove(student);
hiddenStudents.remove(student); // Remove from hidden list as well
_saveStudents();
});
}
@override
Widget build(BuildContext context){
return Scaffold(
appBar: AppBar(
title: Text('Random Student Picker'),
actions: [
IconButton(
icon: Icon(Icons.settings),
onPressed: (){
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Settings will be coming soon'),
),
);
},
),
IconButton(
icon: Icon(Icons.info),
onPressed: (){
// Navigate to about screen
Navigator.push(
context,
MaterialPageRoute(builder: (context)=> AboutScreen()),
);
},
),
],
),
body: ListView.builder(
itemCount: students.length,
itemBuilder: (context, index){
final student = students[index];
return Dismissible(
key: Key(student),
onDismissed: (direction){
deleteStudent(student);
},
background: Container(
color: Colors.red,
child: Icon(Icons.delete),
alignment: Alignment.centerRight,
),
child: ListTile(
title: Text(student),
onTap: (){
toggleVisibility(student);
},
leading: hiddenStudents.contains(student)
? Icon(Icons.visibility_off)
: null,
),
);
},
),
floatingActionButton: FloatingActionButton(
onPressed: pickRandomStudent,
tooltip: 'Pick Random Student',
child: Icon(Icons.sync),
),
);
}
}
class AboutScreen extends StatelessWidget {
@override
Widget build(BuildContext context){
return Scaffold(
appBar: AppBar(
title: Text('About'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'CSCI 4350',
style: TextStyle(fontSize: 24),
),
Image.asset(
'assets/images/piedmont-college-banner.jpg',
width: 200,
height: 200,
),
Text(
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 17th International Conference Dasfaa 2012 Busan South Korea April 2012 Proceedings Part 1 Lncs 7238

Authors: Sang-goo Lee ,Zhiyong Peng ,Xiaofang Zhou ,Yang-Sae Moon ,Rainer Unland ,Jaesoo Yoo

2012 Edition

364229037X, 978-3642290374

More Books

Students also viewed these Databases questions