zipy_flutter 0.0.1 copy "zipy_flutter: ^0.0.1" to clipboard
zipy_flutter: ^0.0.1 copied to clipboard

First release of the zipy_flutter package, compatible with both iOS and Android.

example/lib/main.dart

// ignore_for_file: unused_local_variable

import 'dart:convert';

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:dio/dio.dart';
import 'package:zipy_flutter/zipy_flutter.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized(); // Initialize the binding.
  Zipy.init(key: 'YOUR_API_KEY');
  runApp(const ZipyWrapper(child: MyApp()));
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorObservers: [ZipyNavigationObserver()],
      home: const HomeScreen(),
      routes: {
        '/profile': (context) => const ProfileScreen(),
      },
    );
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  void _throwException() {
    throw Exception('This is a test exception');
  }

  void zipylogs() {
    Zipy.logMessage(
        message: 'Log Message Button Pressed', exceptionObj: {'zipy ': 'test'});
  }

  void zipylogsexception() {
    Zipy.logException(
        message: 'Log Message Button Pressed', exceptionObj: {'zipy ': 'test'});
  }

  Future<void> zipygetsessionurl() async {
    dynamic a = await Zipy.getCurrentSessionURL();
    // print(a);
  }

  Future<void> diogetCall() async {
    final dioClient = ZipyDioClient();
    const String url = 'https://jsonplaceholder.typicode.com/todos/';
    final Map<String, String> headers = {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer diogetCalls',
    };

    try {
      final Response response = await dioClient.get(
        url,
        options: Options(headers: headers),
      );
    } catch (e) {
      print(e);
    }
  }

  Future<void> diopostCall() async {
    final Dio dio = Dio();
    dio.interceptors.add(NetworkLogger());
    final Uri todosUri =
        Uri.parse('https://jsonplaceholder.typicode.com/todos/');

    final Map<String, String> headers = {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer your_api_key',
    };

    final Map<String, dynamic> postData = {
      'title': '2',
      'body': '33',
      'userId': 4343,
    };

    try {
      final response = await dio.post(
        todosUri.toString(),
        data: postData,
        options: Options(headers: headers),
      );
    } catch (e) {
      print('Error posting data: $e');
    }
  }

  Future<void> httpgetCall() async {
    final client = ZipyHttpClient();
    const String url = 'https://jsonplaceholder.typicode.com/posts/';

    final Map<String, String> headers = {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer your_api_key',
    };

    try {
      final response = await client.get(
        Uri.parse(url),
        headers: headers,
      );
    } catch (e) {
      print(e);
    }
  }

  Future<void> httppostCall() async {
    final client = ZipyHttpClient();
    const String url = 'https://jsonplaceholder.typicode.com/posts/';

    final Map<String, String> headers = {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer your_api_key',
    };

    final Map<String, dynamic> postData = {
      'title': 'foo',
      'body': 'bar',
      'userId': 1,
    };

    try {
      final response = await client.post(
        Uri.parse(url),
        headers: headers,
        body: jsonEncode(postData),
      );

      if (response.statusCode == 201) {
        // print('Post successful: ${jsonDecode(response.body)}');
      } else {
        // print('Failed to post: ${response.statusCode}');
      }
    } catch (e) {
      // print('Error posting data: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Zipy Test App'),
      ),
      body: Center(
        child: GridView.count(
          crossAxisCount: 2,
          padding: const EdgeInsets.all(16),
          crossAxisSpacing: 16,
          mainAxisSpacing: 16,
          children: [
            _buildColoredContainer(
              color: const Color(0xFFAFB7FF),
              text: 'Throw Exception',
              onPressed: _throwException,
            ),
            _buildColoredContainer(
              color: const Color(0xFFFFA08B),
              text: 'Zipy Logs',
              onPressed: zipylogs,
            ),
            _buildColoredContainer(
              color: const Color(0xFF8FE8A4),
              text: 'Zipy Exception',
              onPressed: zipylogsexception,
            ),
            _buildColoredContainer(
              color: const Color(0xFF61C2F8),
              text: 'Zipy Get Session URL',
              onPressed: zipygetsessionurl,
            ),
            _buildColoredContainer(
              color: const Color(0xFFF8C261),
              text: 'Dio Get Call',
              onPressed: diogetCall,
            ),
            _buildColoredContainer(
              color: const Color.fromARGB(255, 248, 97, 110),
              text: 'Dio Post Call',
              onPressed: diopostCall,
            ),
            _buildColoredContainer(
              color: const Color(0xFF61C2F8),
              text: 'Http Get Call',
              onPressed: httpgetCall,
            ),
            _buildColoredContainer(
              color: const Color.fromARGB(255, 188, 97, 248),
              text: 'Http Post Call',
              onPressed: httppostCall,
            ),
            _buildColoredContainer(
              color: const Color(0xFFFF96B9),
              text: 'Go to Profile',
              onPressed: () {
                Navigator.pushNamed(context, '/profile');
              },
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildColoredContainer({
    required Color color,
    required String text,
    required VoidCallback onPressed,
  }) {
    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: color,
        borderRadius: BorderRadius.circular(12),
        boxShadow: [
          BoxShadow(
            color: Colors.grey.withOpacity(0.5),
            spreadRadius: 5,
            blurRadius: 7,
            offset: const Offset(0, 3), // changes position of shadow
          ),
        ],
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Text(
            text,
            style: const TextStyle(
                fontSize: 18, color: Colors.black, fontWeight: FontWeight.bold),
            textAlign: TextAlign.center,
          ),
          const SizedBox(height: 16),
          ElevatedButton(
            onPressed: onPressed,
            style: ElevatedButton.styleFrom(
              foregroundColor: Colors.black, backgroundColor: Colors.white,
              padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
              textStyle: const TextStyle(fontSize: 16), // Text color
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(8),
              ),
              elevation: 5,
            ),
            child: const Text('Click'),
          ),
        ],
      ),
    );
  }
}

class ProfileScreen extends StatelessWidget {
  const ProfileScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Profile Screen'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            Navigator.pop(context);
          },
          style: ElevatedButton.styleFrom(
            foregroundColor: Colors.white, backgroundColor: Colors.blue,
            padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
            textStyle: const TextStyle(fontSize: 16), // Text color
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(8),
            ),
            elevation: 5,
          ),
          child: const Text('Back to Home'),
        ),
      ),
    );
  }
}
1
likes
0
points
1.49k
downloads

Publisher

unverified uploader

Weekly Downloads

First release of the zipy_flutter package, compatible with both iOS and Android.

Homepage
Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (license)

Dependencies

dio, flutter, http, path, path_provider, plugin_platform_interface

More

Packages that depend on zipy_flutter