Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.1 kB
1
Indexable
Never
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:url_launcher/url_launcher.dart';

class MyIconButton extends StatelessWidget {
  final String file = 'assets/purple-twitch-logo-png-18.png';
  final Widget navigator;

  const MyIconButton({super.key, required this.navigator});

  Future<void> doLogin() async {
    final url = Uri.parse('http://192.168.1.16:5000/login?scopes=user_read&redirect_uri=http://localhost:8080/auth/twitch/callback');
    if (await canLaunch(url.toString())) {
      await launch(url.toString());
    } else {
      throw 'Could not launch $url';
    }
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: IconButton(
        onPressed: ()  async {
          await doLogin();
          Navigator.push(
            context,
            MaterialPageRoute(builder: (BuildContext context) {
              return navigator;
            }),
          );
        },
        iconSize: 80,
        icon: Image.asset(file),
        tooltip: 'Cliquez pour vous connecter.',
      ),
    );
  }
}