-
-
Save yeasin50/829bf92bd2d4e49ba7622124814e9a50 to your computer and use it in GitHub Desktop.
border-progressBar for SO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter/services.dart'; | |
import 'package:rive/rive.dart'; | |
void main() => runApp( | |
const MyApp(), | |
); | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return const MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: RiveBorder(), | |
); | |
} | |
} | |
class RiveBorder extends StatefulWidget { | |
const RiveBorder({Key? key}) : super(key: key); | |
@override | |
_RiveBorderState createState() => _RiveBorderState(); | |
} | |
class _RiveBorderState extends State<RiveBorder> { | |
StateMachineController? controller; | |
//progress value | |
SMIInput<double>? valueController; | |
// infinite loop | |
SMIInput<bool>? loopController; | |
Artboard? _riveArtboard; | |
_initRive() { | |
rootBundle.load("assets/new_file.riv").then((value) async { | |
final file = RiveFile.import(value); | |
final artboard = file.mainArtboard; | |
controller = | |
StateMachineController.fromArtboard(artboard, "State Machine 1"); | |
if (controller != null) { | |
debugPrint("got state"); | |
setState(() { | |
artboard.addController(controller!); | |
valueController = controller!.findInput('value'); | |
loopController = controller!.findInput('loop'); | |
// ignore: avoid_function_literals_in_foreach_calls | |
controller!.inputs.forEach((element) { | |
debugPrint(element.name); | |
}); | |
}); | |
} | |
_riveArtboard = artboard; | |
}); | |
} | |
@override | |
void initState() { | |
_initRive(); | |
super.initState(); | |
} | |
@override | |
void dispose() { | |
controller?.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Row( | |
mainAxisSize: MainAxisSize.min, | |
children: [ | |
const Text("loop"), | |
const SizedBox( | |
width: 10, | |
), | |
Switch( | |
value: loopController == null ? false : loopController!.value, | |
onChanged: (value) { | |
setState(() { | |
if (loopController != null) loopController!.value = value; | |
}); | |
}, | |
), | |
], | |
), | |
Slider( | |
value: valueController == null ? 0 : valueController!.value, | |
min: 0, | |
max: 100, | |
onChanged: (value) { | |
setState(() { | |
valueController != null ? valueController!.value = value : 0; | |
}); | |
}, | |
), | |
SizedBox( | |
height: 100, | |
width: 100, | |
child: Stack( | |
alignment: Alignment.center, | |
children: [ | |
_riveArtboard == null | |
? const CircularProgressIndicator() | |
: Rive( | |
artboard: _riveArtboard!, | |
), | |
const Icon( | |
Icons.umbrella, | |
size: 77, | |
) | |
], | |
), | |
) | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment