• Как сделать анимированную кнопку play/pouse для плеера без фона со скруглёнными углами?

    RomReed
    @RomReed
    JavaScript, Flutter, ReactNative, Redux, Firebase
    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,
                    ),
                  ),
                ),
              ],
            ),
          ),
        );
      }
    }
    Ответ написан
    Комментировать
  • Как из асинхронной функции вернуть не Future объект?

    @Neonoviiwolf
    Flutter developer
    FutureBuilder(
        future: Future<void>.delayed(const Duration(seconds: 1)),
        builder: (context, snapshot) {
             return SizedBox();
         },
     ),


    FutureBuilder принимает как раз Future и ждёт возвращения результата, состояние можно узнать из snapshot, пока происходит получение даных, показывать загрузку, а как придёт результат, выполнить соответсвенно код. Через Future.microtask для такой задачи использовать не стоит, почитайте что такое microtask в Event Loop In Dart
    Ответ написан
    Комментировать
  • Как из асинхронной функции вернуть не Future объект?

    RomReed
    @RomReed
    JavaScript, Flutter, ReactNative, Redux, Firebase
    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()
            ),
          ),
        );
      }
    }
    Ответ написан
    Комментировать
  • DISCORD.py как получить id канала по его названию? или другой способ отправлять сообщение в канал?

    SoreMix
    @SoreMix Куратор тега Python
    yellow
    channel = discord.utils.get(member.guild.channels, name="Имя")
    Ответ написан
    Комментировать