knt_ui 1.3.0 copy "knt_ui: ^1.3.0" to clipboard
knt_ui: ^1.3.0 copied to clipboard

outdated

A Flutter package contains all handy widgets for Appixi's future projects

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:knt_ui/knt_ui.dart';

import 'generated/assets.gen.dart';
import 'generated/locale_keys.g.dart';
import 'kntgen/generated_page.dart';
import 'repo/poh_repo.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await EasyLocalization.ensureInitialized();
  EasyLocalization.logger.enableBuildModes = [];
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return KntAppWrapper(
      supportedLocales: const [Locale(DefinedSetting.defaultLanguageCode)],
      debugShowPreviewDevice: false,
      appBuilder: (context, devicePreviewLocale, devicePreviewAppBuilder) {
        return MaterialApp(
          title: 'Flutter Demo',
          locale: devicePreviewLocale,
          localizationsDelegates: context.localizationDelegates,
          supportedLocales: context.supportedLocales,
          builder: devicePreviewAppBuilder,
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: const MyHomePage(title: 'Flutter Demo Home Page'),
        );
      },
    );
  }
}

abstract class TabIconMain {
  static final TabIcon home = TabIcon(
    localeKeyTitle: LocaleKeys.main_tabs_home,
    activeImagePath: Assets.images.icHomeTabActive.path,
    inactiveImagePath: Assets.images.icHomeTabUnactive.path,
  );
  static final TabIcon help = TabIcon(
    localeKeyTitle: LocaleKeys.main_tabs_help,
    activeImagePath: Assets.images.icHelpTabActive.path,
    inactiveImagePath: Assets.images.icHelpTabUnactive.path,
  );

  static final List<TabIcon> values = [home, help];
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>
    with SingleTickerProviderStateMixin {
  final _needConcurrent = false;
  final _onTabChanged = ValueNotifier<int>(0);

  Future<String> _loginPoh() async {
    final repo = PohRepo();
    await repo.init();
    return await repo.login(needConcurrent: _needConcurrent);
  }

  @override
  Widget build(BuildContext context) {
    return KntBottomNavScaffold(
      onTabChanged: _onTabChanged,
      appBar: KntAppBar(titlePage: 'KNT demo'),
      icons: TabIconMain.values,
      tabs: [
        SingleChildScrollView(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              FutureBuilder<String>(
                future: _loginPoh(),
                builder: (context, snapshot) {
                  if (snapshot.connectionState == ConnectionState.waiting) {
                    return const KntProgressBar(color: Colors.blue);
                  }
                  if (snapshot.hasError) {
                    return Text(
                      snapshot.error?.toString() ?? '',
                      style: TextStyle(
                        color: Colors.orange,
                        fontSize: 20.sp,
                      ),
                    );
                  }
                  if (snapshot.hasData) {
                    return Text(
                      snapshot.data ?? 'Has empty data',
                      style: TextStyle(
                        color: Colors.orange,
                        fontSize: 20.sp,
                      ),
                    );
                  }
                  return Container(
                    height: 50.w,
                    color: Colors.orange,
                  );
                },
              ),
              KntButton(
                title: LocaleKeys.main_navigate_web.tr(),
                onPressed: () {
                  KntWebPage.push(
                    context,
                    url: 'https://www.google.com',
                  );
                },
              ),
              KntButton(
                title: LocaleKeys.main_navigate_tabHelp.tr(),
                onPressed: () {
                  _onTabChanged.value = 1;
                },
              ),
              KntButton(
                title: LocaleKeys.main_navigate_generatedPage.tr(),
                onPressed: () {
                  GeneratedPage.push(context);
                },
              ),
              KntButton(
                title: 'Show Toast',
                onPressed: () => context.onError('Show fucking noobs!'),
              ),
              KntImage.network(
                width: 256.w,
                height: 256.w,
                uri:
                    'https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse1.mm.bing.net%2Fth%3Fid%3DOIP.uIgI--NBV7O7HCKmv5Ab2gHaFh%26pid%3DApi&f=1',
              ),
              const KntDefaultIssuingWidget(
                errorMessage: 'Abc',
              ),
              const KntChip(text: 'abc'),
              KntDefaultImage(
                width: 64.w,
                height: 64.w,
              ),
            ],
          ),
        ),
        Container(
          color: Colors.orange,
        ),
      ],
    );
  }
}