Reorderable Grid View: Copy From Official ReorderableListView

ReorderableGridView

Copy from official ReorderableListView

Usage:

dependencies:
  reorderable_grid_view: ^2.2.2

Example

class _MyHomePageState extends State<MyHomePage> {
  final data = [1, 2, 3, 4, 5];

  @override
  Widget build(BuildContext context) {
    Widget buildItem(String text) {
      return Card(
        key: ValueKey(text),
        child: Text(text),
      );
    }

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),

      body: Center(
        // use ReorderableGridView.count() when version >= 2.0.0
        // else use ReorderableGridView()
        child: ReorderableGridView.count(
          crossAxisSpacing: 10,
          mainAxisSpacing: 10,
          crossAxisCount: 3,
          children: this.data.map((e) => buildItem("$e")).toList(),
          onReorder: (oldIndex, newIndex) {
            setState(() {
              final element = data.removeAt(oldIndex);
              data.insert(newIndex, element);
            });
          },
          footer: [
            Card(
              child: Center(
                child: Icon(Icons.add),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Other

ReorderableGridView.builder and ReorderableSliverGridView.count can work.

Important

as issue #17 says. There's some broken api in MultiDragGestureRecognizer. So if you have some issue relative to MultiDragGestureRecognizer.

Please try both 1.1.x and 1.2.x version.

TODO

  • impl the ReorderableGrid.extent

Use this package as a library

Depend on it

Run this command:

With Flutter:

 $ flutter pub add reorderable_grid_view

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  reorderable_grid_view: ^2.2.2

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:reorderable_grid_view/reorderable_grid_view.dart';

example/lib/main.dart

import 'package:example/demo_grid_builder.dart';
import 'package:example/demo_grid_sliver.dart';
import 'package:example/test_issue_24.dart';
import 'package:example/test_overlay.dart';
import 'package:flutter/material.dart';
import 'package:reorderable_grid_view/reorderable_grid_view.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      // home: Scaffold(
      //   body: DemoReorderableGrid(),
      // ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

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

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    // return TestIssue24();
    return DefaultTabController(
      length: 4,
      child: Scaffold(
        appBar: AppBar(
          bottom: TabBar(
            tabs: [
              Tab(
                text: "Grid.count",
              ),
              Tab(
                text: "Grid.build",
              ),
              Tab(
                text: "SliverGrid.count",
              ),
              Tab(
                text: "Test Overlay",
              )
            ],
          ),
          title: Text(widget.title!),
        ),
        body: TabBarView(
          children: [
            DemoReorderableGrid(),
            DemoGridBuilder(),
            DemoGridSliver(),
            TestIssue24()
          ],
        ),
      ),
    );
  }
}

class DemoReorderableGrid extends StatefulWidget {
  @override
  _DemoReorderableGridState createState() => _DemoReorderableGridState();
}

class _DemoReorderableGridState extends State<DemoReorderableGrid> {
  final data = List<int>.generate(10, (index) => index);
  double scrollSpeedVariable = 5;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
      child: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: ReorderableGridView.count(
          crossAxisSpacing: 10,
          mainAxisSpacing: 10,
          crossAxisCount: 3,
          childAspectRatio: 0.6, // 0 < childAspectRatio <= 1.0
          children: this.data.map((e) => buildItem(e)).toList(),
          scrollSpeedController:
              (int timeInMilliSecond, double overSize, double itemSize) {
            // print(
            //     "timeInMilliSecond: $timeInMilliSecond, overSize: $overSize, itemSize $itemSize");
            if (timeInMilliSecond > 1500) {
              scrollSpeedVariable = 15;
            } else {
              scrollSpeedVariable = 5;
            }
            return scrollSpeedVariable;
          },
          onReorder: (oldIndex, newIndex) {
            // print("reorder: $oldIndex -> $newIndex");
            setState(() {
              final element = data.removeAt(oldIndex);
              data.insert(newIndex, element);
            });
          },
          dragWidgetBuilder: (index, child) {
            return Card(
              color: Colors.blue,
              child: Text(index.toString()),
            );
          },
          footer: [
            Card(
              child: Center(
                child: Icon(Icons.add),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget buildItem(int index) {
    return Card(
      key: ValueKey(index),
      child: Text(index.toString()),
    );
  }
}

Author: huhuang03
Source code: https://github.com/huhuang03/reorderable_grid_view
License: MIT license

#dart #flutter 

What is GEEK

Buddha Community

Reorderable Grid View: Copy From Official ReorderableListView

Reorderable Grid View: Copy From Official ReorderableListView

ReorderableGridView

Copy from official ReorderableListView

Usage:

dependencies:
  reorderable_grid_view: ^2.2.2

Example

class _MyHomePageState extends State<MyHomePage> {
  final data = [1, 2, 3, 4, 5];

  @override
  Widget build(BuildContext context) {
    Widget buildItem(String text) {
      return Card(
        key: ValueKey(text),
        child: Text(text),
      );
    }

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),

      body: Center(
        // use ReorderableGridView.count() when version >= 2.0.0
        // else use ReorderableGridView()
        child: ReorderableGridView.count(
          crossAxisSpacing: 10,
          mainAxisSpacing: 10,
          crossAxisCount: 3,
          children: this.data.map((e) => buildItem("$e")).toList(),
          onReorder: (oldIndex, newIndex) {
            setState(() {
              final element = data.removeAt(oldIndex);
              data.insert(newIndex, element);
            });
          },
          footer: [
            Card(
              child: Center(
                child: Icon(Icons.add),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Other

ReorderableGridView.builder and ReorderableSliverGridView.count can work.

Important

as issue #17 says. There's some broken api in MultiDragGestureRecognizer. So if you have some issue relative to MultiDragGestureRecognizer.

Please try both 1.1.x and 1.2.x version.

TODO

  • impl the ReorderableGrid.extent

Use this package as a library

Depend on it

Run this command:

With Flutter:

 $ flutter pub add reorderable_grid_view

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  reorderable_grid_view: ^2.2.2

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:reorderable_grid_view/reorderable_grid_view.dart';

example/lib/main.dart

import 'package:example/demo_grid_builder.dart';
import 'package:example/demo_grid_sliver.dart';
import 'package:example/test_issue_24.dart';
import 'package:example/test_overlay.dart';
import 'package:flutter/material.dart';
import 'package:reorderable_grid_view/reorderable_grid_view.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      // home: Scaffold(
      //   body: DemoReorderableGrid(),
      // ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

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

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    // return TestIssue24();
    return DefaultTabController(
      length: 4,
      child: Scaffold(
        appBar: AppBar(
          bottom: TabBar(
            tabs: [
              Tab(
                text: "Grid.count",
              ),
              Tab(
                text: "Grid.build",
              ),
              Tab(
                text: "SliverGrid.count",
              ),
              Tab(
                text: "Test Overlay",
              )
            ],
          ),
          title: Text(widget.title!),
        ),
        body: TabBarView(
          children: [
            DemoReorderableGrid(),
            DemoGridBuilder(),
            DemoGridSliver(),
            TestIssue24()
          ],
        ),
      ),
    );
  }
}

class DemoReorderableGrid extends StatefulWidget {
  @override
  _DemoReorderableGridState createState() => _DemoReorderableGridState();
}

class _DemoReorderableGridState extends State<DemoReorderableGrid> {
  final data = List<int>.generate(10, (index) => index);
  double scrollSpeedVariable = 5;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
      child: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: ReorderableGridView.count(
          crossAxisSpacing: 10,
          mainAxisSpacing: 10,
          crossAxisCount: 3,
          childAspectRatio: 0.6, // 0 < childAspectRatio <= 1.0
          children: this.data.map((e) => buildItem(e)).toList(),
          scrollSpeedController:
              (int timeInMilliSecond, double overSize, double itemSize) {
            // print(
            //     "timeInMilliSecond: $timeInMilliSecond, overSize: $overSize, itemSize $itemSize");
            if (timeInMilliSecond > 1500) {
              scrollSpeedVariable = 15;
            } else {
              scrollSpeedVariable = 5;
            }
            return scrollSpeedVariable;
          },
          onReorder: (oldIndex, newIndex) {
            // print("reorder: $oldIndex -> $newIndex");
            setState(() {
              final element = data.removeAt(oldIndex);
              data.insert(newIndex, element);
            });
          },
          dragWidgetBuilder: (index, child) {
            return Card(
              color: Colors.blue,
              child: Text(index.toString()),
            );
          },
          footer: [
            Card(
              child: Center(
                child: Icon(Icons.add),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget buildItem(int index) {
    return Card(
      key: ValueKey(index),
      child: Text(index.toString()),
    );
  }
}

Author: huhuang03
Source code: https://github.com/huhuang03/reorderable_grid_view
License: MIT license

#dart #flutter 

NumPy Copies and Views - Copy Vs View in NumPy

NumPy consists of different methods to duplicate an original array. The two main functions for this duplication are copy and view. The duplication of the array means an array assignment. When we duplicate the original array, the changes made in the new array may or may not reflect. The duplicate array may use the same location or may be at a new memory location.

NumPy copy and View

Copy or Deep copy in NumPy

It returns a copy of the original array stored at a new location. The copy doesn’t share data or memory with the original array. The modifications are not reflected. The copy function is also known as deep copy.

import numpy as np
arr = np.array([20,30,50,70])
a= arr.copy()
#changing a value in original array
arr[0] = 100

print(arr)
print(a)

Output

[100 30 50 70]

[20 30 50 70]

Changes made in the original array are not reflected in the copy.

import numpy as np
arr = np.array([20,30,50,70])
a= arr.copy()
#changing a value in copy array
a[0] = 5

print(arr)
print(a)

Output

[20 30 50 70]

[ 5 30 50 70]

Changes made in copy are not reflected in the original array

#numpy tutorials #numpy copy #numpy views #numpy

Monotone: An Unsplash Application for IOS

Monotone

Monotone is a Modern Mobile Application, integrated with powerful Unsplash API provided by Unsplash. It implemented almost all features including viewing, searching, collecting photos. And other features, such as profile, license, FAQ are supported as well.

This is an un-official application, exploring the feasibility of some conceptions is the goal of this project. Written in Swift, triggered by RxSwift, draw responsive constraints using SnapKit.

If you like this project or inspired by any ideas of this project, please star it without any hesitation. (ヽ(✿゚▽゚)ノ)

Overview

screen-record-1.gif screen-record-2.gif



 

Development Progress

Features

  •  Write Interfaces Programmatically
  •  Dark Mode Support
  •  Animation Effects
  •  Localization
  •  Powered by Unsplash API
  •  More...

Tasks

Currently supported tasks:

PositionModulePageStyle & LayoutPowered by DataAnimation EffectsLocalization
MainLoginSign Up & Sign In
PhotoList (Search & Topic)
View
Camera Settings
Collect (Add & Remove)
Share to SNS⬜️
Save to Album
Side MenuProfileDetails
MenuMy Photos
Hiring⬜️
Licenses
Help⬜️
Made with Unsplash⬜️
Tab BarStoreHome⬜️
Details⬜️
WallpaperList (Adapt Screen Size)⬜️
CollectionList
ExploreList (Photo & Collection)⬜️



 

Getting Started

This application uses Cocoapods to manage dependencies. Please refer to Cocoapods Offical Website to install & configure(If you already installed Cocoapods, skip this).

Prerequisites

Monotone is trigged by Unsplash API . The very first thing must be done is applying a pair of OAuth key to run it.

  1. Visit Unsplash, sign up then sign in.(If you already have an account, skip this).
  2. Visit Unsplash Application Registration Platform agree with terms and create a new application, the application name and description can be anything.
  3. After the application was created,it will redirect to the application details page automatically (Also can be found from https://unsplash.com/oauth/applications). At Redirect URI & Permissions - Redirect URI section, input monotone://unsplash, make sure all authentication options are checked, just like the image shown below.

  1. After the work is finished, check ”Access Key“ and ”Secret Key“ on this page, they will be used soon.

Installation

  1. Execute the following commands in the terminal:
# Clone to a local folder
git clone https://github.com/Neko3000/Monotone.git

# Direct to Project folder
cd Monotone

# Install Pods
pod install
  1. Under Monotone folder, duplicate config_debug.json file,and rename it to config.json(This file is ignored by .gitignore);
  2. Open config.json ,input your ”Access Key“ and ”Secret Key“,they will be copyed to APP folder when running.(For more information, please refer to the content in Project->Build Phases->Run Script and APPCredential.swift );
  3. Done,command + R。

     

Dependencies

ProjectDescription
RxSwiftFramework for Reactive Async Programming.
ActionBased on RxSwift,encapsulate actions for calling。
DataSourcesBased on RxSwift,extend logic interaction of tableview and collectionview。
AlamofireHTTP network library.
SwiftyJSONHandle JSON format data effectively.
ObjectMapperMap data between models and JSON.
KingfisherNetwork image cache libray with many functions.
SnapKitMake constraints effectively.
......

For more information,please check Podfile

Project Structure

The basic structure of this project.

Monotone 
├── Monotone
│   ├── /Vars  #Global Variables
│   ├── /Enums  #Enums (Includes some dummy data)
│   ├── /Application
│   │   ├── AppCredential  #Authentication Credential
│   │   ...
│   │   └── UserManager  #User Managment
│   ├── /Utils  #Utils
│   │   ├── /BlurHash  #Photo Hash
│   │   ├── ColorPalette  #Global Colors
│   │   ├── AnimatorTrigger  #Animation Effects
│   │   └── MessageCenter  #Message Notification
│   │── /Extension  #Extensions
│   │── /Services  #Services
│   │   ├── /Authentication  #Requests of Authentication
│   │   └── /Network  #Requesets of Data
│   │── /Components  #View Classes
│   │── /ViewModels  #View Models
│   │── /ViewControllers  #View Controllers
│   │── /Models  #Data Models
│   │── /Coordinators  #Segues
│   └── /Resource  #Resource
└── Pods


Designing

The interface you are seeing are all designed by Addie Design Co. They shared this document, everyone can free download it and use it. Those design elements and their level of completion are astonishing. This application would not be here without this design document.

Thanks again to Addie Design Co and this beautiful design document.



 

About Unsplash

Unsplash is a website dedicated to sharing high-quality stock photography under the Unsplash license. All photos uploaded by photographers will be organized and archived by editors.

And this website is one of my favorites, admired for its artistic, the spirit of sharing.
You will find my home page here. (Not updated frequently since 2020)



 

Contributing

Limited by data Unsplash API provides, some parts of this application only finished their styles and layouts(Almost in store, explore, etc). If the API provides more detailed data on these parts in the future, we will add new features as soon as possible.

Meanwhile, focusing on the current application, we will improve it continuously.

How to Participate in

If you are an experienced mobile application developer and want to improve this application. You are welcomed to participate in this open-source project. Practice your ideas, improve even refactor this application.

Follow standard steps:

  1. Fork this repo;
  2. Create your new Branch (git checkout -b feature/AmazingFeature);
  3. Add Commit (git commit -m 'Add some AmazingFeature');
  4. Push to remote Branch (git push origin feature/AmazingFeature);
  5. Open a Pull Request.

For anyone, open an issue if you find any problems. PRs are welcome.


Author: Neko3000
Source code: https://github.com/Neko3000/Monotone
License: MIT license

#swift 

Harsha  Shirali

Harsha Shirali

1669174554

Replace Elements in Python NumPy Array with Example

In this article, we will learn how to replace elements in Python NumPy Array. To replace elements in Python NumPy Array, We can follow the following examples.

Example 1 : Replace Elements Equal to Some Value

The following code shows how to replace all elements in the NumPy array equal to 8 with a new value of 20:

#replace all elements equal to 8 with 20
my_array[my_array == 8] = 20

#view updated array
print(my_array)

[ 4  5  5  7 20 20  9 12]

Example 2: Replace Elements Based on One Condition

The following code shows how to replace all elements in the NumPy array greater than 8 with a new value of 20:

#replace all elements greater than 8 with 20
my_array[my_array > 8] = 20

#view updated array
print(my_array)

[ 4  5  5  7  8  8 20 20]

Example 3: Replace Elements Based on Multiple Conditions

The following code shows how to replace all elements in the NumPy array greater than 8 or less than 6 with a new value of 20:

#replace all elements greater than 8 or less than 6 with a new value of 20
my_array[(my_array > 8) | (my_array < 6)] = 20

#view updated array
print(my_array)

[20 20 20  7  8  8 20 20]

#python 
 

Rusty  Bernier

Rusty Bernier

1593629580

Episode #15: Python Regular Expressions, Views vs Copies in Pandas, and More

Have you wanted to learn Regular Expressions in Python, but don’t know where to start? Have you stumbled into the dreaded pink SettingWithCopyWarning in Pandas? This week on the show, we have David Amos from the Real Python team to discuss a recent two-part series on Regex in Python. We also talk about another recent article on the site about views vs copies in Pandas. David also brings a few other articles and projects from the wider Python community for us to discuss.

#python #pandas #views #copies