psk907 / fluttermoji

A light-weight and highly customizable SVG graphic set for Flutter which generates avatars and provides a Customizer Widget, personalized CircleAvatar and other utility functions.
https://pub.dev/packages/fluttermoji
MIT License
72 stars 50 forks source link

Default Svg image get display while using SvgPicture.string(encoded) #2

Closed kanwarmanraj closed 3 years ago

kanwarmanraj commented 3 years ago

Default Svg image get display while using SvgPicture.String(decoded), First I encode the current FluttermojiCircleAvatar using the FluttermojiFunctions and then decode it to display with the help of SvgPicture.String(decoded).

psk907 commented 3 years ago

@kanwarmanraj could you please elaborate on the issue you're facing.

kanwarmanraj commented 3 years ago

I am encoding the Svg using final encoded = await _fluttermojiFunctions.encodeMySVGtoString(); So that I can send it to the server and Later I am decoding it like bytes: _fluttermojiFunctio.decodeFluttermojifromString(encoded), But every time I make any change to the avatar, encoded String do change. But SvgPicture.String(decoded), shows the default SVG only, even if the encoded string changes. image Heres the screenshot of my emulator

class MyHomePage extends StatelessWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;
  FluttermojiFunctions _fluttermojiFunctions = FluttermojiFunctions();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
        centerTitle: true,
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.all(16.0),
              child: Text(
                "Use your Fluttermoji anywhere\nwith the below widget",
                style: TextStyle(fontWeight: FontWeight.w600, fontSize: 20),
                textAlign: TextAlign.center,
              ),
            ),
            FluttermojiCircleAvatar(
              backgroundColor: Colors.grey[200],
              radius: 100,
            ),
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text(
                "and create your own page to customize them using our widgets",
                style: TextStyle(fontWeight: FontWeight.w600, fontSize: 20),
                textAlign: TextAlign.center,
              ),
            ),
            RaisedButton.icon(
                icon: Icon(Icons.edit),
                label: Text("Customize"),
                onPressed: () async {
                  final encoded =
                      await _fluttermojiFunctions.encodeMySVGtoString();
                  print(encoded);

                  Navigator.push(
                      context,
                      new MaterialPageRoute(
                          builder: (context) => NewPage(
                                bytes: _fluttermojiFunctions
                                    .decodeFluttermojifromString(encoded),
                              )));
                })
          ],
        ),
      ),
    );
  }
}

class NewPage extends StatelessWidget {
  final String bytes;
  const NewPage({Key key, @required this.bytes}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: <Widget>[
            Row(
              children: [
                FluttermojiCircleAvatar(
                  radius: 100,
                ),
                SvgPicture.string(
                  bytes,
                  height: 150,
                )
              ],
            ),
            FluttermojiCustomizer(
                // scaffoldHeight: 200,
                // scaffoldWidth: 200,
                ),
          ],
        ),
      ),
    );
  }
}

and here's the code for it, And by the way really fabulous package you have created

psk907 commented 3 years ago

Thank you @kanwarmanraj . I think I've figured what's causing the bug, it's a conditional statement that is causing it. I shall assign myself to this issue and fix it.

psk907 commented 3 years ago

I have fixed the bug in commit 3bfe55857a80dc320e4b2c5ba45fe41514c2d9a9 and pushed changes. Please check it out and let me know : )

kanwarmanraj commented 3 years ago

Yes, it's working good now, thank you. I want to ask one thing is there any way to customize the save button? like by using something like FluttermojiController fluttermojiController=FluttermojiController(); then fluttermojiController.setFluttermoji(....)

psk907 commented 3 years ago

fluttermojiController.setFluttermoji() will save the currently set attributes, yes. However the save button is baked into the FluttermojiCustomizer widget, so currently there is no way to customize the save button directly.

kanwarmanraj commented 3 years ago

ok , is there any other parameter which is required to be put while initializing the controller, Because fluttermojiController.setFluttermoji(); gives an error

E/flutter (17366): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Invalid argument(s)
E/flutter (17366): #0      List.[] (dart:core-patch/array.dart:191:52)
E/flutter (17366): #1      ListMixin.elementAt (dart:collection/list.dart:78:33)
E/flutter (17366): #2      FluttermojiController._getFluttermojiProperty (package:fluttermoji/fluttermojiController.dart:54:10)
E/flutter (17366): #3      FluttermojiController.getFluttermojiFromOptions (package:fluttermoji/fluttermojiController.dart:82:26)
E/flutter (17366): #4      FluttermojiController.setFluttermoji (package:fluttermoji/fluttermojiController.dart:67:24)
E/flutter (17366): #5      MyHomePage.build.<anonymous closure> (package:circle/main.dart:32:33)
E/flutter (17366): #6      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:993:19)
E/flutter (17366): #7      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1111:38)
psk907 commented 3 years ago

I've used the GetX approach in the package , so if you want to use the FluttermojiController on your own, you will have to initialize _fluttermojiController with an existing instance of the class.

You may do that adding the following code to your initState() -

_fluttermojiController = Get.find<FluttermojiController>();

If you do not have instance running , you will get an error , you can get around that by adding -

Get.put(FluttermojiController());

before initializing your variable.

You will have to depend on the get package in your pubspec.yaml for this workaround.

Hope this helps 😄

kanwarmanraj commented 3 years ago

Great!! thanks a lot, it worked really well now.