import 'package:flutter/material.dart'; import 'package:function_types/function_types.dart'; import 'button.dart'; import 'loading.dart'; class GitHostSetupSshKeyKnownProvider extends StatelessWidget { final Func0 doneFunction; final Func0 regenerateFunction; final Func1 copyKeyFunction; final String publicKey; final Func0 openDeployKeyPage; GitHostSetupSshKeyKnownProvider({ @required this.doneFunction, @required this.regenerateFunction, @required this.copyKeyFunction, @required this.openDeployKeyPage, @required this.publicKey, }); @override Widget build(BuildContext context) { if (publicKey == null || publicKey.isEmpty) { return GitHostSetupLoadingPage("Generating SSH Key ..."); } var columns = Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'In order to access this repository, this public key must be copied as a deploy key', style: Theme.of(context).textTheme.title, ), const SizedBox(height: 32.0), // Step 1 Text( '1. Copy the key', style: Theme.of(context).textTheme.subtitle, ), const SizedBox(height: 8.0), PublicKeyWidget(publicKey), const SizedBox(height: 8.0), GitHostSetupButton( text: "Copy Key", onPressed: () => copyKeyFunction(context), ), GitHostSetupButton( text: "Regenerate Key", onPressed: regenerateFunction, ), const SizedBox(height: 16.0), // Step 2 Text( '2. Open webpage, and paste the deploy key. Make sure it is given Write Access. ', style: Theme.of(context).textTheme.subtitle, ), const SizedBox(height: 8.0), GitHostSetupButton( text: "Open Deploy Key Webpage", onPressed: openDeployKeyPage, ), const SizedBox(height: 16.0), // Step 3 Text( '3. Try Cloning ..', style: Theme.of(context).textTheme.subtitle, ), const SizedBox(height: 8.0), GitHostSetupButton( text: "Clone Repo", onPressed: doneFunction, ), ], ); return Center( child: SingleChildScrollView( child: columns, ), ); } } class GitHostSetupSshKeyUnknownProvider extends StatelessWidget { final Func0 doneFunction; final Func1 copyKeyFunction; final String publicKey; GitHostSetupSshKeyUnknownProvider({ @required this.doneFunction, @required this.copyKeyFunction, @required this.publicKey, }); @override Widget build(BuildContext context) { if (publicKey == null || publicKey.isEmpty) { return GitHostSetupLoadingPage("Generating SSH Key ..."); } var columns = Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'In order to access this repository, this public key must be copied as a deploy key', style: Theme.of(context).textTheme.title, ), const SizedBox(height: 32.0), // Step 1 Text( '1. Copy the key', style: Theme.of(context).textTheme.subtitle, ), const SizedBox(height: 8.0), PublicKeyWidget(publicKey), const SizedBox(height: 8.0), GitHostSetupButton( text: "Copy Key", onPressed: () => copyKeyFunction(context), ), const SizedBox(height: 16.0), // Step 2 Text( '2. Give this SSH Key access to the git repo. (You need to figure it out yourself)', style: Theme.of(context).textTheme.subtitle, ), const SizedBox(height: 16.0), // Step 3 Text( '3. Try Cloning ..', style: Theme.of(context).textTheme.subtitle, ), const SizedBox(height: 8.0), GitHostSetupButton( text: "Clone Repo", onPressed: doneFunction, ), ], ); return Center( child: SingleChildScrollView( child: columns, ), ); } } class GitHostSetupKeyChoice extends StatelessWidget { final Func0 onGenerateKeys; final Func0 onUserProvidedKeys; GitHostSetupKeyChoice({ @required this.onGenerateKeys, @required this.onUserProvidedKeys, }); @override Widget build(BuildContext context) { return Container( child: Column( children: [ Text( "We need SSH keys to authenticate -", style: Theme.of(context).textTheme.headline, ), const SizedBox(height: 16.0), GitHostSetupButton( text: "Generate new keys", onPressed: onGenerateKeys, ), const SizedBox(height: 8.0), GitHostSetupButton( text: "Provide Custom SSH Keys", onPressed: onUserProvidedKeys, ), ], mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, ), ); } } class GitHostUserProvidedKeys extends StatefulWidget { final Func2 doneFunction; GitHostUserProvidedKeys({ @required this.doneFunction, }); @override _GitHostUserProvidedKeysState createState() => _GitHostUserProvidedKeysState(); } class _GitHostUserProvidedKeysState extends State { final _publicKeyController = TextEditingController(); final _privateKeyController = TextEditingController(); @override Widget build(BuildContext context) { return Container( child: Column( children: [ Text( "Public Key -", style: Theme.of(context).textTheme.headline, ), const SizedBox(height: 8.0), KeyEditor(_publicKeyController), const SizedBox(height: 8.0), Text( "Private Key -", style: Theme.of(context).textTheme.headline, ), KeyEditor(_privateKeyController), const SizedBox(height: 16.0), GitHostSetupButton( text: "Next", onPressed: () { var publicKey = _publicKeyController.text.trim(); var privateKey = _privateKeyController.text.trim(); widget.doneFunction(publicKey, privateKey); }, ), ], mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, ), ); } } // FIXME: vHanda: Add validation class KeyEditor extends StatelessWidget { final TextEditingController controller; KeyEditor(this.controller); @override Widget build(BuildContext context) { return SizedBox( width: double.infinity, height: 80.0, child: Container( color: Theme.of(context).buttonColor, child: SingleChildScrollView( child: Container( padding: const EdgeInsets.all(8.0), child: TextField( controller: controller, textAlign: TextAlign.left, maxLines: null, style: Theme.of(context).textTheme.body1, ), ), ), ), ); } } class PublicKeyWidget extends StatelessWidget { final String publicKey; PublicKeyWidget(this.publicKey); @override Widget build(BuildContext context) { return SizedBox( width: double.infinity, height: 160.0, child: Container( color: Theme.of(context).buttonColor, child: SingleChildScrollView( child: Container( padding: const EdgeInsets.all(8.0), child: Text( publicKey, textAlign: TextAlign.left, maxLines: null, style: Theme.of(context).textTheme.body1, ), ), ), ), ); } }