Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Task/Task\2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:flutter/material.dart';
import 'package:todo2/home.dart';

void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: HomePage(),
));
}

40 changes: 40 additions & 0 deletions Task2/checkBox.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:flutter/material.dart';

class Check extends StatelessWidget {
final bool isActive;

const Check({Key? key, required this.isActive}) : super(key: key);

@override
Widget build(BuildContext context) {
if (isActive) {
return Container(
width: 30,
height: 30,
decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.pink),
child: Icon(
Icons.check,
size: 20,
color: Colors.white,
),
);
} else {
return Container(
width: 30,
height: 30,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
border: Border.all(
color: Colors.grey,
width: 3,
)),
child: Icon(
Icons.check,
size: 20,
color: Colors.white,
),
);
}
}
}
143 changes: 143 additions & 0 deletions Task2/home.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:todo2/home.dart';
import 'package:todo2/todo.dart';

class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
Map<String, dynamic> todo = {};
TextEditingController _controller = new TextEditingController();

@override
void initState() {
_loadData();
}

_loadData() async {
SharedPreferences storage = await SharedPreferences.getInstance();

if (storage.getString('todo') != null) {
var storage2 = storage;
var string = storage2.getString('todo');
todo = jsonDecode(string!);
}
}

@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: SafeArea(
child: Scaffold(
appBar: AppBar(
title: Text('Todo App'),
backgroundColor: Colors.pink,
),
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 30,
),
Expanded(
child: ListView.builder(
itemCount: todo.length,
itemBuilder: (context, data) {
return Dismissible(
key: Key('item' + data.toString()),
onDismissed: (direction) {
todo.remove(todo.keys.elementAt(data));
_save();
},
child: InkWell(
onTap: () {
setState(() {
todo[todo.keys.elementAt(data)] =
!todo[todo.keys.elementAt(data)];
});
_save();
},
child: TodoItem(
name: todo.keys.elementAt(data),
isActive: todo.values.elementAt(data)),
),
);
},
),
)
],
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Scaffold(
appBar: AppBar(
backgroundColor: Colors.pink,
),
body: Container(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
controller: _controller,
keyboardType: TextInputType.multiline,
maxLines: null,
decoration: InputDecoration(
hintText: 'Write....',
),
),
),
//actions:
FlatButton(
child: Text(
'save',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold),
),
onPressed: () {
Navigator.pop(context);
_addTodo();
},
),
//child: child)
],
),
))));
},
child: Icon(Icons.add),
backgroundColor: Colors.pink,
),
),
),
);
}

_addTodo() async {
setState(() {});
SharedPreferences storage = await SharedPreferences.getInstance();

if (_controller.text.length > 0) {
setState(() {
todo.putIfAbsent(_controller.text, () => false);
storage.setString('todo', jsonEncode(todo));
});
}
setState(() {});
}

_save() async {
SharedPreferences storage = await SharedPreferences.getInstance();

storage.setString('todo', jsonEncode(todo));
}
}
9 changes: 9 additions & 0 deletions Task2/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:flutter/material.dart';
import 'package:todo2/home.dart';

void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: HomePage(),
));
}
69 changes: 69 additions & 0 deletions Task2/todo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

import 'package:todo2/checkBox.dart';

class TodoItem extends StatefulWidget {
final String name;
final bool isActive;

const TodoItem({Key? key, required this.name, required this.isActive})
: super(key: key);

@override
_TodoItemState createState() => _TodoItemState();
}

class _TodoItemState extends State<TodoItem> {
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 50),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: MediaQuery.of(context).size.width / 100 * 50,
child: Text(
widget.name,
style: TextStyle(
fontSize: 17,
color: Colors.black,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
softWrap: true,
),
),
/////////////////////////////////
Row(
children: [
Text(
DateFormat('d ').format(DateTime.now()),
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: Colors.black45),
),
Text(
DateFormat('MMM ').format(DateTime.now()).toUpperCase(),
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.black45),
),
Text(
DateFormat('y').format(DateTime.now()),
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.black45),
),
],
),

/////////////////////////////////
Check(
isActive: widget.isActive,
)
],
),
);
}
}
Binary file added Task3/images/clear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Task3/images/cloudy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Task3/images/forest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Task3/images/nighcity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Task3/images/rainy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Task3/images/snow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Task3/images/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Task3/images/sunset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Task3/images/thunderstorm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions Task3/lib/cubit/weather_cubit.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:bloc/bloc.dart';
import 'package:meta/meta.dart';
import 'package:flutter_application_6/models/forecast.dart';
import 'package:flutter_application_6/services/repository.dart';

part 'weather_state.dart';

class WeatherCubit extends Cubit<WeatherState> {
final IRepository _repository;
WeatherCubit(this._repository)
: super(WeatherInitial('Please enter city name.'));

Future<void> getWeather(String cityName, bool isFavourite) async {
try {
emit(WeatherLoading());
final forecast = await _repository.getWeather(cityName.trim());
forecast.city = cityName;
//forecast.isFavourite = isFavourite;
emit(WeatherLoaded(forecast: forecast));
} catch (_) {
if (cityName.isEmpty) {
emit(WeatherError("Please enter city name."));
} else if (_.toString().contains('error retrieving location for city')) {
emit(WeatherError("City not found."));
} else {
emit(WeatherError("Network error, please try again"));
}
}
}
}
22 changes: 22 additions & 0 deletions Task3/lib/cubit/weather_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
part of 'weather_cubit.dart';

@immutable
abstract class WeatherState {}

class WeatherInitial extends WeatherState {
final String message;
WeatherInitial(this.message);
}

class WeatherLoading extends WeatherState {}

class WeatherLoaded extends WeatherState {
final Forecast forecast;

WeatherLoaded({required this.forecast}) : super();
}

class WeatherError extends WeatherState {
final String message;
WeatherError(this.message);
}
16 changes: 16 additions & 0 deletions Task3/lib/di/initialize_dependency.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:get_it/get_it.dart';
import 'package:flutter_application_6/services/repository.dart';
import 'package:flutter_application_6/services/weather_api.dart';
import 'package:http/http.dart' as http;

GetIt injector = GetIt.instance;

Future<void> initializeDependency() async {
injector.registerSingleton<http.Client>(http.Client());

injector
.registerSingleton<IWeatherApi>(WeatherApi(injector.get<http.Client>()));

injector
.registerSingleton<IRepository>(Repository(injector.get<IWeatherApi>()));
}
Loading