int getDaysInMonth(DateTime date) {
DateTime firstDayOfNextMonth = (date.month < 12)
? DateTime(date.year, date.month + 1, 1)
: DateTime(date.year + 1, 1, 1);
//проблема у тебя была тут. Ты сам у себя сьел 1 день
DateTime lastDayOfMonth = firstDayOfNextMonth.subtract(Duration(seconds: 1));
return lastDayOfMonth.day;
}
void main() {
DateTime date = DateTime(2024, 3, 1); // Пример: 1 марта 2024 года
int daysInMonth = getDaysInMonth(date);
print("Количество дней в месяце: $daysInMonth");
}
import 'package:socket_io_client/socket_io_client.dart' as IO;
class SocketManager {
static final SocketManager _instance = SocketManager._internal();
factory SocketManager() => _instance;
IO.Socket? _socket;
SocketManager._internal();
// Метод для создания или получения экземпляра соединения
IO.Socket get socket {
if (_socket == null) {
_socket = IO.io('https://your_socket_server_url');
}
return _socket!;
}
}
import 'package:flutter/material.dart';
import 'package:your_project_name/socket_manager.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: FirstPage(),
);
}
}
class FirstPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
// Получение соединения Socket.IO
final socket = SocketManager().socket;
return Scaffold(
appBar: AppBar(title: Text('First Page')),
body: Center(
child: ElevatedButton(
onPressed: () {
// Подключение к Socket.IO серверу
socket.connect();
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondPage()),
);
},
child: Text('Go to Second Page'),
),
),
);
}
}
class SecondPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
// Получение соединения Socket.IO
final socket = SocketManager().socket;
return Scaffold(
appBar: AppBar(title: Text('Second Page')),
body: Center(
child: ElevatedButton(
onPressed: () {
// Отключение от Socket.IO сервера
socket.disconnect();
Navigator.pop(context);
},
child: Text('Go back to First Page'),
),
),
);
}
}
import 'package:flutter/material.dart';
class PlayPauseButton extends StatefulWidget {
final bool isPlaying;
final VoidCallback onPressed;
PlayPauseButton({required this.isPlaying, required this.onPressed});
@override
_PlayPauseButtonState createState() => _PlayPauseButtonState();
}
class _PlayPauseButtonState extends State<PlayPauseButton> with SingleTickerProviderStateMixin {
late AnimationController _animationController;
late Animation<double> _animation;
@override
void initState() {
super.initState();
_animationController = AnimationController(
duration: Duration(milliseconds: 300),
vsync: this,
);
_animation = Tween<double>(begin: 0.0, end: 1.0).animate(_animationController);
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
@override
void didUpdateWidget(covariant PlayPauseButton oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.isPlaying) {
_animationController.forward();
} else {
_animationController.reverse();
}
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: widget.onPressed,
child: Container(
width: 50,
height: 50,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.transparent,
),
child: Stack(
children: [
Center(
child: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black,
),
),
),
Center(
child: ScaleTransition(
scale: _animation,
child: Icon(
widget.isPlaying ? Icons.pause : Icons.play_arrow,
size: 30,
color: Colors.white,
),
),
),
],
),
),
);
}
}
abstract class Model {
List<String> getFields();
}
class Data extends Model {
late final int field1;
late final int field2;
Data({required this.field1, required this.field2});
@override
List<String> getFields() {
return ["field1", "field2"];
}
}
class Table<T extends Model> {
final List<T> dataList;
late List<String> fieldList;
Table({required this.dataList, required T instance}) {
if (dataList.isEmpty) {
fieldList = instance.getFields();
} else {
fieldList = dataList.first.getFields();
}
}
}
class MyApp extends StatefulWidget {
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool? isLoggedIn;
Future<void> checkLoggedIn() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
bool? isLoggedIn = prefs.getBool('isLogin');
this.setState(() {
isLoggedIn = isLoggedIn;
});
}
@override
void initState() {
super.initState();
Future.microtask(() async => await checkLoggedIn());
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'MY APP',
debugShowCheckedModeBanner: false,
scrollBehavior: MyCustomScrollBehavior(),
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: SingleChildScrollView(child:
isLoggedIn != null?
isLoggedIn!
? Main()
: Login()
: OpenScreen()
),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter_/style.dart';
class Registration extends StatefulWidget {
@override
State<Registration> createState() => _Registration();
}
class _Registration extends State<Registration> {
final _nameController = TextEditingController();
final _passwordController = TextEditingController();
Widget button(text, linc) {
return ElevatedButton(
style: ElevatedButton.styleFrom(
primary: s.buttonColor, minimumSize: Size(2500, 70)),
onPressed: () {
Navigator.pushNamed(context, linc);
submitForm();
},
child: Text("${text}", style: TextStyle(color: Colors.white)),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: s.backgroundColor,
appBar: AppBar(
centerTitle: true,
backgroundColor: s.appBarColor,
title: Text("Регистрация", style: TextStyle(color: Colors.white)),
),
body: Center(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 100, vertical: 100),
child: Column(
children: [
Icon(
Icons.watch_later,
color: s.buttonColor,
size: 150,
),
SizedBox(
height: 50,
),
TextFormField(
controller: _nameController,
decoration: InputDecoration(labelText: "Имя пользователя"),
),
TextFormField(
controller: _passwordController,
decoration: InputDecoration(labelText: "Пароль"),
),
SizedBox(
height: 50,
),
button("Зарегистрироваться", "/home_page_schedule")
],
)),
));
}
void submitForm() {
print("Name ${_nameController.text}");
}
}